2

このようなコマンドを実行したいのですが、関数handle (self,*args,**options)はネストされた関数を実行していないようです。

関数を に含めるにはどうすればよいhandle()ですか?

from django.core.management.base import NoArgsCommand

class Command(NoArgsCommand):
    def handle(self, *args, **options):
        def hello():
            print "hello1"
        def hello1():
            print "hello2"
4

1 に答える 1

3

関数を「オンザフライ」で定義することもできます。

class Command(NoArgsCommand):
    def handle_noargs(self):
        def hello():
            print "hello1"

        def hello1():
            print "hello2"

        hello()
        hello1()

またはコマンドの外側(「サービス」が機能する場所など):

def hello():
    print "hello1"

def hello1():
    print "hello2"


class Command(NoArgsCommand):

    def handle_noargs(self):
        hello()
        hello1()
于 2012-04-20T08:55:20.523 に答える