No worries. I figured it out at the end. I'm sorry but I forgot to mention that the code was inside a file other than my main.py file, a sort of initialization file if you will. As a first fix-around I decided to open the file in both my main.py and initialization.py files, but that didn't work.
Then in my initialization.py file I wrote:
at the very beginning that way it would be considered a global variable and I would be able to use it inside any of my post-defined functions. Problem is I wanted to use it inside of class methods that I would define in initialization.py but that I would be calling from my main.py file. The first fix I tried was opening, writing and closing the output.txt file inside of the different class methods of initialization.py. That didn't work so I changed to class methods to make them return a string and in my main.py file I would write:
Code: Select all
output = open("output.txt", "w") # At the beginning of the program
output.write(class_instance.method()) # Whenever I would need to 'write' the results of calling a class method
output.close() # At the end of the program
Thank you for your help anyway deshipu!