-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathch17.py
More file actions
59 lines (42 loc) · 997 Bytes
/
Copy pathch17.py
File metadata and controls
59 lines (42 loc) · 997 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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# -*- coding: utf-8 -*-
# read files
f = open('users.txt')
users = f.readlines() # read all the text into a list
user1 = f.readline() # read one line in text
user2 = f.readline()
user3 = f.readline()
user4 = f.readline()
f.close() # After using, please close the file
# write into files
f = open('users.txt','r+')
f.write('test')
f.close()
f = open('users.txt')
lines = f.readlines()
for line in lines:
print line
f = open('users.txt','w')
lines[0]='Jacob\n'
f.writelines(lines)
# add into files
f = open('users.txt','a')
line = 'Zumba'
f.write(line)
f.close()
f = open('users.txt')
f.readlines()
# get the infromation
import os
current_dir = os.getcwd()
os.listdir(current_dir)
os.listdir('.')
os.listdir('/tmp/')
os.walk('.')
os.makedir()
os.makedirs()
stats = os.stat('README.txt')
stats.st_size
stats.st_atime
stats.st_mtime
from datetime import datetime
datetime.fromtimestamp(stats.st_atime)