以下内容都在一个文件中。 definner_foo(in_arg ) :
全局x;
x =99
return in_arg 1
defouter_foo(in_arg ) :
全局x;
x=0
output=inner_foo(in_arg )
返回输出
result=outer_foo(5)
打印(' result ',result ) )。
打印(' x==',x ) ) ) ) ) ) )。
当一切都在一个文件中时,运行得很好。 打印内容如下。
^{pr2}$
但是,如果尝试用多个文件分割程序,就会出现问题。 #在# CONTENTS OF inner_foo.py上
definner_foo(in_arg ) :
全局x;
x =99
return in_arg 1
这是另一个文件。 # CONTENTS OF outer_foo.py
from inner_foo import inner_foo
defouter_foo(in_arg ) :
全局x
x=0
output=inner_foo(in_arg )
返回输出
result=outer_foo(5)
打印(' result ',result ) )。
打印(' x==',x ) ) ) ) ) ) )。
{{cd2内部错误}_食品为
将import语句更改为包含x(frominner_fooimportinner_foo,x )将得到importerror : cannotimportname ' x '