Skip to content

Commit bcd729f

Browse files
committed
__name__ to prevent unnessary call
1 parent 4153da0 commit bcd729f

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-5
lines changed

_46_demo.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11

2-
print('hello '+__name__)
2+
print('hello from demo'+__name__)
33

44
def main():
55

66
print('hello')
77
print('welcome user')
88

99
if __name__ == '__main__':
10-
main()
10+
main() # to prevent call if just imported
11+
12+
# main()

_46_specialvariable__name__.py

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11

22

3-
import _46_demo
3+
# print(__name__) # __main__
4+
# print('hello'+__name__) # hello__main__
45

5-
# print(__name__)
6-
print('hello'+__name__)
6+
import _46_demo #hello from demo_46_demo
7+
8+
# print(__name__) # __main__
9+
print('hello from sp'+__name__) # hello from sp__main__
710
print("its time to calculate")
811

912

__pycache__/_46_demo.cpython-312.pyc

410 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)