'problem with import classes and subclasses, need __init__.py explications
ok, i clarify
into my main_folder
--- main_file.py
import classeA
import A1.classeA1
import A1.A2.classeA2
import A1.A2.A3.classeA3
mainwin= tk.Tk()
objA= classeA.A()
print(objA.nom)
objA1= A1.classeA1.A1()
print(objA1.nom)
objA2= A1.A2.classeA2.A2()
print(objA2.nom)
--- classeA.py
class A():
def __init__(self, nom="A"):
self.nom= nom
--- subfolderA1
------ classeA1.py
class A1():
def __init__(self, nom="A1"):
self.nom= nom
------ subfolderA2
--------- classeA2.py
class A2():
def __init__(self, nom="A2"):
self.nom= nom
As you can read, i can make objects from (or into) main_file.py, but there is not inheritance.
If i decide:
class A2 inherits from class A1
and/or
class A1 inherits from class A
i don't know how and where to write my import instructions
with
class A1 inherits from class A
class A1(A):
def __init__(self, nom="A1"):
self.nom= nom
i tried many ways
into classeA.py
import A1.classeA1.A1
return: name A is not defined
import A1.classeA1
return: same
and others
there is something i don't write, i forget, i write with bad syntax.
i tried with sys.path.insert:
the same
so maybe init.py files, i did not try yet.
Anyone to tell me what i'm wrong and/or i forget.
Thank you
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
