Skip to main content
Stack Overflow
  1. About
  2. For Teams

Return to Answer

Post Timeline

putPut the code inside a function and it won't run until you call the function. You should have a main function in your main.pymain.py. with the statement:

if __name__ == '__main__': main()

thenThen, if you call "python main.py"python main.py the main()main() function will run. If you import main.pymain.py, it will not. Also, you should probably rename main.pymain.py to something else for clarityclarity's sake.

put the code inside a function and it won't run until you call the function. You should have a main function in your main.py. with the statement:

if __name__ == '__main__': main()

then, if you call "python main.py" the main() function will run. If you import main.py, it will not. Also, you should probably rename main.py to something else for clarity sake.

Put the code inside a function and it won't run until you call the function. You should have a main function in your main.py. with the statement:

if __name__ == '__main__': main()

Then, if you call python main.py the main() function will run. If you import main.py, it will not. Also, you should probably rename main.py to something else for clarity's sake.

added 1 character in body
Source Link
sniperd
  • 5.3k
  • 6
  • 32
  • 49

put the code inside a function and it won't run until you call the function. You should have a main function in your main.py. with the statement:

if __name__ === '__main__': main()

then, if you call "python main.py" the main() function will run. If you import main.py, it will not. Also, you should probably rename main.py to something else for clarity sake.

put the code inside a function and it won't run until you call the function. You should have a main function in your main.py. with the statement:

if __name__ = '__main__': main()

then, if you call "python main.py" the main() function will run. If you import main.py, it will not. Also, you should probably rename main.py to something else for clarity sake.

put the code inside a function and it won't run until you call the function. You should have a main function in your main.py. with the statement:

if __name__ == '__main__': main()

then, if you call "python main.py" the main() function will run. If you import main.py, it will not. Also, you should probably rename main.py to something else for clarity sake.

Source Link
Matt
  • 87
  • 1
  • 1

put the code inside a function and it won't run until you call the function. You should have a main function in your main.py. with the statement:

if __name__ = '__main__': main()

then, if you call "python main.py" the main() function will run. If you import main.py, it will not. Also, you should probably rename main.py to something else for clarity sake.

lang-py

AltStyle によって変換されたページ (->オリジナル) /