May-01-2019, 06:04 PM
How do I save the values a variable to a text file in Python 3? i.e. my_varialbe = 'This is the text content" write my_variable to my_variable.txt Thank you!
Print to Text file in Python 3
|
May-01-2019, 06:04 PM
How do I save the values a variable to a text file in Python 3? i.e. my_varialbe = 'This is the text content" write my_variable to my_variable.txt Thank you!
May-01-2019, 07:42 PM
You can do
from pathlib import Path Path('my_variable.txt').write_text(my_variable)
May-02-2019, 04:38 AM
Is file already existing and have content? If existing and with content - do you want to write it to new line or at the end of existing line?
One way to write (append) to file: >>> my_variable = 'This is the text content.' >>> with open('my_variable.txt', 'a') as f: ... f.write(my_variable)
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy
Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame. |
|