Skip to content

Commit ed40f35

Browse files
author
ashegde
committed
feat(examples): file system
1 parent 4363eae commit ed40f35

File tree

6 files changed

+50
-0
lines changed

6 files changed

+50
-0
lines changed

codes/session_5/hello.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Hello World!
2+
My name is Ashwin Hegde, I work as a Software Engineer
3+
My primary language is JavaScript and Secondary language is Python
4+
Python is needed for scripting, Machine Learning and Quantum Programming

codes/session_5/read.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Open terminal > python3 read.py
2+
# Start typing below commands and see the output
3+
4+
with open('hello.txt') as f:
5+
data = f.read()
6+
print(data)
7+
f.closed

codes/session_5/readline.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Open terminal > python3 readline.py
2+
# Start typing below commands and see the output
3+
4+
f = open('hello.txt', 'r')
5+
print(f.readline())
6+
print(f.readline())
7+
print(f.readline())
8+

codes/session_5/sample.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Hello World! My name is Ashwin

codes/session_5/seekTell.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Open terminal > python3 seekTell.py
2+
# Start typing below commands and see the output
3+
4+
f = open('sample.txt', 'r')
5+
6+
f.seek(8, 0) # 0 mean beginning of the file
7+
print(f.read())
8+
9+
print('\n\n')
10+
11+
# f.seek(8, 1) # 1 mean current position
12+
# print(f.read())
13+
14+
# print('\n\n')
15+
16+
# f.seek(-3, 2) # 2 mean end of the file
17+
# print(f.read())
18+

codes/session_5/write.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Open terminal > python3 write.py
2+
# Start typing below commands and see the output
3+
4+
fw = open('hello.txt', 'a')
5+
totalWrittenChar = fw.write('\nPython is needed for scripting, Machine Learning and Quantum Programming')
6+
print('Total written characters are ' + repr(totalWrittenChar))
7+
fw.close()
8+
9+
with open('hello.txt') as fr:
10+
data = fr.read()
11+
print(data)
12+
fr.close()

0 commit comments

Comments
 (0)