-1

I have 2 files. file_one.py

import file_two

print("File one __name__ is set to: {}" .format(__name__))

file_two.py

print("File two __name__ is set to: {}" .format(__name__))

when i run file_one.py

its printing:

File two __name__ is set to: file_two

File one __name__ is set to: __main__

Why is python printing the line from file_two : "File two name is set to: file_two"

I have only imported file_two, not printing anything from file_two

see example from here:

https://www.freecodecamp.org/news/if-name-main-python-example/

buran
  • 13,682
  • 10
  • 36
  • 61

1 Answers1

-3

You should add this:

if __name__ == '__main__':

before your print statements. See What does if __name__ == "__main__": do?.

I break things
  • 326
  • 3
  • 12