I've been trying to create a class with an __init__
method which will gather some of it's data from another object's attributes. The following code is a bare bone demonstration of my problem.
main.py
import foo
import rat
Archive = foo.Foo()
A = rat.Rat()
rat.py
import foo
class Rat:
def __init__(self):
self.name = "Hi there"
self.birthday = Archive.tick
foo.py
import rat
class Foo:
def __init__(self):
self.tick = 5
As you can guess, this doesn't work and it tells me:
in __init__
self.birthday = Archive.tick
NameError: name 'Archive' is not defined
I don't understand why it tells me Archive is not defined
. Why can't it access the instance I just created? Why does this happen and how can I go around this?
PS: I know it's generally a terrible idea to access an object's attributes in such a public way, but the foo
class is here just to have a general data gathering object, nothing serious.