python中的函数声明有一个可读和干净的代码?

ban*_*anx 7 python syntax declaration

是否可以在python中声明函数并在以后或在单独的文件中定义它们?

我有一些代码:

class tata:
   def method1(self):
      def func1():
         #  This local function will be only used in method1, so there is no use to
         # define it outside.
         #  Some code for func1.
      # Some code for method1.
Run Code Online (Sandbox Code Playgroud)

问题是代码变得混乱且难以阅读.所以我想知道是否有可能在func1内部声明method1并在以后定义它?

unu*_*tbu 6

好没问题:

foo.py:

def func1():
    pass
Run Code Online (Sandbox Code Playgroud)

script.py:

import foo
class tata:
   def method1(self):
      func1=foo.func1
Run Code Online (Sandbox Code Playgroud)