Skip to content

Commit 80a3cfd

Browse files
author
youssif-sully
committed
update_2
1 parent b91d76e commit 80a3cfd

File tree

7 files changed

+94
-21
lines changed

7 files changed

+94
-21
lines changed

4_Importing_Modules/main.py

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,46 @@
1+
###############################################
2+
# #
3+
# Created by Youssef Sully #
4+
# Beginner python #
5+
# Importing modules #
6+
# main.py #
7+
# #
8+
###############################################
9+
110
# importing the module
211
import module_3
312
# importing the module_2 and 'renaming' it for ease of use
4-
# names should be relevent
13+
# names should be relevant
514
import module_2 as mod2
615

716
# importing 1 variable and function from (module_1)
817
# note the second variable CAN'T be accessed.
9-
from module_1 import str_mod_1, multiplicationTable
18+
from module_1 import str_mod_1, functionModule1
19+
20+
print("\n{} {} {}\n".format("-" * 9, "Using . to call an variable in "
21+
"module_3 (import module_3)", "-" * 9))
1022

1123
# by specifying the the name of the module first followed by .
12-
# the content of that module can be accessed
13-
print("\n")
24+
# the content of that module can be accessed
1425
print(module_3.str_mod_3)
26+
27+
print("\n{} {} {}\n".format("-" * 9, "Using mod2. to call an variable in "
28+
"module_2 (import module_2 as mod2)", "-" * 9))
29+
1530
print(mod2.str_mod_2)
1631

17-
# note that if (from import) used, the variable (str_mod_1) and the function
32+
print("\n{} {} {}\n".format("-" * 9, "Without . to call an variable and a function in "
33+
"module_1 (from module_1 import str_mod_1, "
34+
"multiplicationTable)", "-" * 9))
35+
36+
# note that if (from import) used, the variable (str_mod_1) and the function
1837
# (multiplicationTable()) are defined in the main.py but NOT the module itself
1938
print(str_mod_1)
20-
print(multiplicationTable())
39+
functionModule1()
40+
41+
print("\n{} {} {}\n".format("-" * 9, "Error: Using . to call an variable in "
42+
"module_1 because from is used(from module_1 "
43+
"import str_mod_1, multiplicationTable)", "-" * 9))
2144

2245
# ERROR: name 'module_1' is not defined
23-
print(module_1.str_mod_1)
46+
print(module_1.str_mod_1)

4_Importing_Modules/module_1.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
1+
###############################################
2+
# #
3+
# Created by Youssef Sully #
4+
# Beginner python #
5+
# Importing modules #
6+
# module_1.py #
7+
# #
8+
###############################################
9+
110
print("Hello from module_1, contents: 2 variables and a function")
211

312
str_mod_1 = 'this a variable in module_1'
413
int_mod_1 = 13
514

6-
def multiplicationTable():
7-
8-
for i in range(1, 11):
9-
print("\n")
10-
for j in range(1 ,11):
11-
print("{:02} * {:02} = {:02} |".format(i, j, i * j), end=' ')
12-
1315

16+
def functionModule1():
17+
print("Hi i'm function in module_1")

4_Importing_Modules/module_2.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
###############################################
2+
# #
3+
# Created by Youssef Sully #
4+
# Beginner python #
5+
# Importing modules #
6+
# module_2.py #
7+
# #
8+
###############################################
9+
110
print("Hello from module_2, contents: 1 variable")
211

3-
str_mod_2 = 'this a variable in module_2'
12+
str_mod_2 = 'this a variable in module_2'

4_Importing_Modules/module_3.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
###############################################
2+
# #
3+
# Created by Youssef Sully #
4+
# Beginner python #
5+
# Importing modules #
6+
# module_3.py #
7+
# #
8+
###############################################
9+
110
print("Hello from module_3, contents: 1 variable")
211

3-
str_mod_3 = 'this a variable in module_3'
12+
str_mod_3 = 'this a variable in module_3'

5_File_Handling/file_handling_1.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
###############################################
2+
# #
3+
# Created by Youssef Sully #
4+
# Beginner python #
5+
# File handling 1 #
6+
# #
7+
###############################################
8+
19
# 'r' read, 'w' write, 'a' append and 'r+' read and write
210

311
# Not recommended implementation (close the resources (Ex. files and Network ports ) is imperative

5_File_Handling/file_handling_2.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
###############################################
2+
# #
3+
# Created by Youssef Sully #
4+
# Beginner python #
5+
# File handling 1 #
6+
# #
7+
###############################################
8+
9+
with open('test.txt', 'r') as opened_file:
10+
text_block = 12
11+
12+
print(opened_file.read(text_block), end='')
13+
print("File CURRENT position {}\n".format(opened_file.tell()))
14+
15+
print(opened_file.read(text_block), end='')
16+
print("File CURRENT position {}\n".format(opened_file.tell()))
17+
18+
opened_file.seek(52)
19+
print("File CURRENT position set to {} using seek()".format(opened_file.tell()))
20+
print(opened_file.read(text_block))

5_File_Handling/test.txt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
1. This test.txt file
2-
2. Second line
3-
3. Third line
4-
4. Fourth line
5-
5. Last (fifth) line
1+
1. 1st line
2+
2. 2nd line
3+
3. 3rd line
4+
4. 4th line
5+
5. 5th line

0 commit comments

Comments
 (0)