forked from zhanwen/PythonDataScience
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUserFile.py
More file actions
34 lines (29 loc) · 558 Bytes
/
UserFile.py
File metadata and controls
34 lines (29 loc) · 558 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# open file demo
# mode="r" r(readyonly)
f = open("data.txt", mode="r")
s = f.read()
# print(s)
f.close()
# another way
# not need manual close file
with open("data.txt") as f:
text = f.read()
# print(text)
# read n byte
f = open("data.txt", mode="r")
s = f.read(10)
# print(s)
f.close()
# read next one line
f = open("data.txt", mode="r")
s = f.readline()
# print(s)
f.close()
# read full
f = open("data.txt", mode="r")
s = f.readlines()
# print(s)
f.close()
with open("data.txt", mode="w+b") as f:
line = b"new context "
f.write(line)