I am using Python for automating a complex procedure that has few options. I want to have the following structure in python. - One "flow-class" containing the flow - One helper class that contains a lot of "black boxes" (functions that do not often get changed).
99% of the time, I modify things in the flow-class so I only want code there that is often modified so I do not have to scroll around a lot to find the code I want to modify. This class also contains global variables (configuration settings) that often get changed. The helper class contains global variables that not often get changed.
In the flow-class I have a global variable that I want the user to be forced to input at every run. The line looks like this. print ("Would you like to see debug output (enter = no)? ") debug = getUserInput()
The getUserInput() function should be located in the helper class as it is never modified. The getUserInput needs a global variable from the flow class, which indicates whether the user input should be consistent with Linux command line or Eclipse (running on Windows).
My question is: How can I structure this in the best way? Currently it looks like the following: The flow-class:
import helper_class
isLinux = 1
debug = getUserInput()
The helper-class:
import os, flow_class
def getUserInput():
userInput = input ()
if (flow_class.isLinux == 1):
userInput = userInput[:-1]
return userInput
This currently gives me the following error due to the cross importing:
Traceback (most recent call last):
File "flow_class.py", line 1, in <module>
import helper_class
File "helper_class.py", line 1, in <module>
import os, flow_class
File "flow_class.py", line 5, in <module>
debug = getUserInput()
NameError: name 'getUserInput' is not defined
I know that I could obviously solve this by always passing isLinux as a parameter to getUserInput, but this complicates the usage of this method and makes it less intuitive.