I have a main.py
and a module named gui.py
which im want to compile to cython and then exe which includes:
import gui
if __name__ == '__main__':
gui()
then in the gui.py
I have a code with using if __name__ == '__main__':
as follows:
def find_regex_1(k, s):
reg = f'{k}\s*=\s*(\S+)'
return re.search(reg, s).group(1)
def read_configs(config_file):
with open(config_file, "r") as f:
content = f.read()
license_code = find_regex_1('LICENSE CODE', content)
activation_code = find_regex_1('ACTIVATION CODE ', content)
return license_code, activation_code
if __name__ == '__main__':
license_code, activation_code = read_configs('config.txt')
the second if __name__ == '__main__':
in the gui.py
interrupt the process what I should do to avoid that? I think I should use something else rather than if __name__ == '__main__':
but i don't know what to replace with the same effect
error I'm getting:
C:\Users\Administrator\Desktop\cython>python main.py
Traceback (most recent call last):
File "C:\Users\Administrator\Desktop\cython\main.py", line 24, in <module>
import gui
File "gui.py", line 530, in init gui
status, msg = activate_license(sys.argv[0])
File "gui.py", line 113, in gui.activate_license
"key": license_code,
NameError: name 'license_code' is not defined
when I run the module gui.py
itself it will run with no issue but with main.py
I will get this error