How do I use classes in python? Do I import them?
For example:
class classA:
def __init__(self):
print "class A"
class classB:
def __init__(self):
classA_list = []
for i in range(5):
classA_list.append(classA()) #list of classA objects
This works if I have both classes in one file. But if the classes are saved in two different files, classA as classA.py and classB as classB.py, I get an error shown below. How can I fix this?
>>> classB()
Traceback (most recent call last):
File "<pyshell#2>", line 1, in <module>
classB()
File "C:\ClassB.py", line 19, in __init__
classA_list.append(classA())
NameError: global name 'classA' is not defined
Thanks