When using the import command, I noticed that the imported module is being executed during the import itself, instead of being executed at the appropriate time in my code.
Notice that the print commands are not executed. However, Python is executing MaquinaEstado
during the import itself.
I need the module to be imported so that maquina_estado.prepara_cmos_controle()
and maquina_estado.start(cmos_repo, controle)
are executed in the correct order.
Here is an example:
from main.process_handle import MaquinaEstado
if __name__ == "__main__":
maquina_estado = MaquinaEstado()
print('passo 0 - run_pdv')
cmos_repo, controle = maquina_estado.prepara_cmos_controle()
print('passo 0.1 - run_pdv')
maquina_estado.start(cmos_repo, controle)
The methods contained in MaquinaEstado
are executed as I perform the import. However, my expectation is that they are loaded into memory to be used within the if statement.
Raimundo Viana is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.