Latest web development tutorials

arquivo Python IO

Document Object Reference Exemplos Python3

O código a seguir demonstra as operações de arquivo básico do Python, incluindo abrir, ler, escrever:

# 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)

Executar os resultados de saída do código acima:

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

Document Object Reference Exemplos Python3