[Python-de] import Problem
Hermann Riemann
nospam.ng at hermann-riemann.de
Fr Jan 11 09:42:14 EST 2019
Am 11.01.19 um 11:28 schrieb Achim Herwig:
>> mb.py:
> # fehlt:
> from ma import *
>
>> def b():
>> global z
>> # viel code
>> print("in b")
>> a()
>> # viel code
>> Der Aufruf von
>> from ma import *
>> from mb import *
>> a()
>>
>> liefert:
>> Traceback (most recent call last):
>> File "mm.py", line 4, in <module>
>> a()
>> File "/y/g/py.modul/ma.py", line 8, in a
>> if z>0: b()
>> NameError: name 'b' is not defined
Wohl nicht.:
> python3 mm.py
in a
Traceback (most recent call last):
File "mm.py", line 4, in <module>
a()
File "/y/g/py.modul/ma.py", line 8, in a
if z>0: b()
NameError: name 'b' is not defined
>for i in *.py;do echo "***************" $i;cat $i;done
*************** ma.py
z=6
def a():
global z
# viel code
print("in a")
z-=1
if z>0: b()
# viel code
*************** mb.py
from ma import *
def b():
global z
# viel code
print("in b")
a()
# viel code
*************** mm.py
from ma import *
from mb import *
a()
*************** o.py
z=6
def a():
global z
# viel code
print("in a")
z-=1
if z>0: b()
# viel code
def b():
global z
# viel code
print("in b")
a()
# viel code
a()
Bei import scheint zu gelten:
a will b vorher haben,
b will a vorher haben,
Hermann
der einen großes Programm
gerne zerlegen würde,
aber dann obigen Problemtyp hat.
--
http://www.hermann-riemann.de
Mehr Informationen über die Mailingliste python-de