“Python Guardar la salida en el archivo” Código de respuesta

Cómo escribir en un archivo de salida en Pytion

#first arg is the name of the file
#second arg notes that the file is open to write to it
outputFile = open("fileName", "w")
#next line writes to the file
outputFile.write(str)
#remember to close opened files
outputFile.close()
NitroPog

Impresión de salida Python a archivo

print("Hello stackoverflow!", file=open("output.txt", "a"))
print("I have a question.", file=open("output.txt", "a"))
Jolly Jellyfish

Python Guardar la salida en el archivo

with open("output.txt", "a") as f:
    print("Hello StackOverflow!", file=f)
    print("I have a question.", file=f)
Inexpensive Ibis

Guardar la salida de Python en el archivo de texto

$ python my_program.py > output.txt
Marton

Respuestas similares a “Python Guardar la salida en el archivo”

Preguntas similares a “Python Guardar la salida en el archivo”

Más respuestas relacionadas con “Python Guardar la salida en el archivo” en Python

Explore las respuestas de código populares por idioma

Explorar otros lenguajes de código