Latest web development tutorials

File Python IO

Dokumen Referensi Object contoh Python3

Kode berikut menunjukkan Python operasi file dasar, termasuk membuka, membaca, menulis:

# Filename : test.py
# author by : www.w3big.com

# 写文件
with open("test.txt", "wt") as out_file:
    out_file.write("该文本会写入到文件中\n看到我了吧!")
 
# Read a file
with open("test.txt", "rt") as in_file:
    text = in_file.read()
 
print(text)

Mengeksekusi hasil kode output di atas:

该文本会写入到文件中
看到我了吧!

Dokumen Referensi Object contoh Python3