-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplayingWithFiles.py
More file actions
37 lines (27 loc) · 894 Bytes
/
Copy pathplayingWithFiles.py
File metadata and controls
37 lines (27 loc) · 894 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
import time
with open(r"/var/log/dmesg", 'r') as sudoFile:
while True:
contents = sudoFile.read(80)
if contents:
print contents
# time.sleep(1)
else:
break
print "File /var/log/dmesg Close status: " + str(sudoFile.closed)
with open("chinese.txt", 'r') as chinaFile:
contents = chinaFile.read()
print "Length of the contents: " + str( len(contents))
print contents
print "In Python 2, str is not a string! It's just a sequence of bytes."
for c in contents:
print c
utfStr = contents.decode('utf-8')
print utfStr
print "Length of the decode contents: " + str(len(utfStr))
for c in utfStr:
print c
print "The Last character is " + utfStr[2]
with open("chinese.txt", 'rb') as chinaBinary:
contents = chinaBinary.read()
print type(contents)
print contents