Python如何读写文本文件

Jackey Python 1,532 次浏览 , 没有评论
# 如何读写文本文件
s = '你好'

print(s.encode('utf8'))
print(s.encode('gbk'))

# b 代表byte
print(b'abc')

# wt t 是默认方式
f = open('py3.txt', 'wt', encoding='utf8')

f.write('你好,ijackey.com')

f.close()

f = open('py3.txt', 'rt', encoding='utf8')

s = f.read()

print(s)

 

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注

Go