There are two files in the scope of this problem, let’s call them file1.py and file2.py.
I’ve imported file2.py into file1.py.
I instantiate a class in file1.py and I’d like to access it in file2.py. I’ve tried referencing the object directly (just the class name) but that doesn’t work. How can I reference the object? I don’t want to move this to the same file, it’d make it messy.
Is there a non-hackish way to do this? If not, have I implemented a faulty design?
You need to pass the class from somewhere in File1.py to one of the classes in file.2.
You can simply pass a reference to the class when you invoke the method in file2.py where you need to use it.
Or you can write a “Set….” Method and pass the reference and store it in one of the classes in file2.py.
You could also make it a global static variable — but you would get refused entry to the better coding clubs if you did this.