[Python-de] import Problem

Hermann Riemann nospam.ng at hermann-riemann.de
Fr Jan 11 05:18:16 EST 2019


Gegeben große Datei mit

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

Die soll zerlegt werden in
ma.py:

z=6

def a():
    global z
    # viel code
    print("in a")
    z-=1
    if z>0: b()
    # viel code

mb.py:

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

Hermann
    der gerne große Dateien mit Python3
    Programmen zerlegen würde,
    ohne obiges Problem zu haben,
    oder es mit Tricks wie indirekter Programmaufruf
    zu umgehen.

-- 
http://www.hermann-riemann.de


Mehr Informationen über die Mailingliste python-de