Is it possible to declare functions and implement them separately in python ?
I mean something like in C :
void foo();
void foo()
{
}
解决方案
C forward declarations are used to work around dependency problems. Function foo is used by function bar, and foo needs bar to exist before you can declare it:
void bar()
{
if (condition) { foo(); }
}
void foo()
{
if (condition) { bar(); }
}
won't compile because foo hasn't been declared yet; void foo(); is the C spelling for I know what I am doing, compiler, accept that foo will exist later.
There are no such dependency problems in Python, as global names are looked up at runtime; they don't have to yet exist at compile time.
In other words, this just works:
def bar():
if condition: foo()
def foo():
if condition: bar()
because bar and foo are resolved at runtime.