'How to change the attribute of an instance from an another file?
I am new to oop and I had a doubt.
Suppose we are in the main file and had an instance of a class say bot
and, bot.var = 5
How do I edit bot.var in an another file such that the changes are reflected in the main file as well? Thanks for the help.
main.py :
class Foo:
...
bar = Foo()
bar.var = 5
print(bar.var)
file.py :
from main import Foo
class EditFoo(Foo):
def __init__(self) -> None:
super().__init__()
# What do I do from here
# such that the edits here are reflected on the main.py file
Thanks for the help
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
