# 文件模式 - 创建 f = open('test.txt', 'w') f.write('dzm') f.close()
try: f = open('test.txt', 'wb') f.write('xyq'.encode()) finally: if f: f.close()
with open('test.txt', 'wb') as f: f.write('xyq'.encode())