day 7 作业

# # str --> utf-8
s1 = 'www中国'
b1 = s1.encode('utf-8')
print(b1)

# str --> gbk
s1 = 'www中国'
b1 =s1.encode('gbk')
print(b1)

# utf-8 -->bytes
b3 = b'wwwxe4xb8xadxe5x9bxbd'
s = b3.decode('utf-8')
print(s) #www中国

#gbk -->bytes
b4 = s.encode('gbk')
print(b4) #b'wwwxd6xd0xb9xfa'

f = open(r"D:a.txt",'r',encoding = 'utf-8')
print(f.read())
f.close()


f1 = open('r模式',encoding = 'utf-8')
for line in f1:
print(line)
f1.close()

with open('timg.jpg',mode = 'rb') as f3:
content=f3.read()
with open('timg2.jpg',mode = 'wb') as f4:
f4.write(content)
f3.close()
f4.close()
原文地址:https://www.cnblogs.com/andyyangpython/p/10495388.html