I have program with two files; main.py that has my main logic and class.py which has my classes. My problem is that I can’t figure out how to call a function in main.py from a function in a class in class.py. Here’s a simple example:
in class1.py
class Class1:
def __init__(self, value):
self.value = value
def main_logic(self):
if self.value == 'y':
return self.value
else:
self.value == 'n':
#main()?? How would I call main() in main.py?
in main.py
def display1():
print('Main Menu')
def main():
create_obj = Class1(value1)
new_object = Class1.main_logic()
if new_object == 'y':
display1()
if __name__ == '__main__':
main()
Of course if there is a better way to structure something like this I could use some help there as well.
This is generally not the best method of writing code, but you could:
import main; main.display1()(orimport whateverTHEfileNAMEisif its not main.py) like so: