-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4e2d446
commit 9000c17
Showing
13 changed files
with
99 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
>>> a = b'\x02\xA1\x80' | ||
>>> a | ||
b'\x02\xa1\x80' | ||
>>> a[0] | ||
2 | ||
>>> a[1] | ||
161 | ||
>>> a[2] | ||
128 | ||
>>> a[3] | ||
Traceback (most recent call last): | ||
File "<stdin>", line 1, in <module> | ||
IndexError: index out of range | ||
>>> type(a) | ||
<class 'bytes'> | ||
>>> list(a) | ||
[2, 161, 128] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
>>> a = b'ab_*' | ||
>>> list(a) | ||
[97, 98, 95, 42] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
>>> a = bytes([1, 129, 231]) | ||
>>> a | ||
b'\x01\x81\xe7' | ||
>>> list(a) | ||
[1, 129, 231] | ||
>>> a[1:3] | ||
b'\x81\xe7' | ||
>>> a = bytes([1, 260]) | ||
Traceback (most recent call last): | ||
File "<stdin>", line 1, in <module> | ||
ValueError: bytes must be in range(0, 256) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
with open('src.png', 'rb') as src: | ||
data = src.read() | ||
with open('dst.png', 'wb') as dst: | ||
dst.write(data) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# Reading Characters of File | ||
>>> f = open("info.txt", "r") | ||
>>> f.read(6) | ||
'Hello;' | ||
>>> f.read(6) | ||
'\nI am ' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# Reading Lines of File | ||
f = open("Info.txt", "r") | ||
lines = [] | ||
while True: | ||
line = f.readline() | ||
if line == '': | ||
break # end of file | ||
lines.append(line) | ||
lines.reverse() | ||
for line in lines: | ||
print(line, end = '') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# Writing in File | ||
n = int(input()) | ||
f = open("dst.txt", "w") | ||
for i in range(n): | ||
line = input() | ||
f.write(line + '\n') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# File Pointer | ||
>>> f = open("test.txt", "w") | ||
>>> f.tell() | ||
0 | ||
>>> f.write("salam") | ||
5 | ||
>>> f.tell() | ||
5 | ||
>>> f.write("ali") | ||
3 | ||
>>> f.tell() | ||
8 | ||
|
||
f = open("a.txt", "r") | ||
l, r = (int(x) for x in input().split()) | ||
f.seek(l) | ||
s = f.read(r - l + 1) | ||
print(s) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# Closing File | ||
with open("file address", "opening mode") as f: | ||
#tasks to do with file | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# Application of Generators in Files | ||
def csv_reader(path): | ||
file = open(path) | ||
result = file.read().split("\n") | ||
return result | ||
|
||
def csv_reader(path): | ||
with open(path) as file: | ||
for row in file: | ||
yield row |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Hello; | ||
I am Mohamadreza. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
f = open("file address", "opening mode") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# File Object | ||
>>> f = open('a.txt') | ||
>>> f | ||
<_io.TextIOWrapper name='a.txt' mode='r' encoding='UTF-8'> | ||
>>> type(f) | ||
<class '_io.TextIOWrapper'> |