Cómo escribir.archivos txt en Python 3
Tengo un archivo .txt
en la misma carpeta que este archivo .py
y tiene esto en él:
cat\n
dog\n
rat\n
cow\n
¿Cómo puedo guardar un var (var = 'ant') en la siguiente línea del archivo .txt
?
24
1 answers
Abra el archivo en modo anexar y escriba una nueva línea (incluyendo un separador de líneas \n
):
with open(filename, 'a') as out:
out.write(var + '\n')
Esto agrega la línea al final del archivo después de todos los demás contenidos.
53
Author: Martijn Pieters,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2013-12-06 16:50:49
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2013-12-06 16:50:49