Skip to content

Commit 747aa63

Browse files
authored
Merge pull request #11 from the-code-experiments/develop
feat(example): modules
2 parents ace70a7 + 665eede commit 747aa63

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

codes/session_4/message.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# message.py is a module (imported inside module.py)
2+
# so execute python3 module.py
3+
# Start typing below commands and see the output
4+
5+
def hello(name):
6+
print('Hello ' + name)
7+
8+
def welcome(name):
9+
print('Welcome ' + name)

codes/session_4/module.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Open terminal >
2+
# python3 module.py
3+
# python3 module.py <String>
4+
# Start typing below commands and see the output
5+
6+
# Import module
7+
from message import hello, welcome
8+
# from message import *
9+
# import message # then use as message.hello
10+
11+
print(hello('Ashwin'))
12+
print(welcome('Ashwin'))
13+
14+
if __name__ == '__main__':
15+
import sys
16+
if len(sys.argv) > 1:
17+
hello(sys.argv[1])
18+
else:
19+
hello('Unknown')

0 commit comments

Comments
 (0)