參考:
-
-
# f = open("test4.txt", 'w')
-
#
-
# f.write(b'hello world') # TypeError: write() argument must be str, not bytes
-
#
-
# f.close()
-
-
f = open( "test4.txt", 'wb') # 二進制寫模式
-
-
f.write( b'hello world') # 二進制寫
-
-
f.close() # 關閉文件
-
-
f = open( "test4.txt", 'rb') # 二進制讀
-
-
print(f.read()) # b'hello world' 打印讀出來的數據
-
-
f.close() # 關閉文件
-