Ask coding questions

← Back to all posts
Save .txt File In Python
lightningrock

How do you save a .text file in python?

I add content and it works well but when I refresh it all the content disappears! So how do you get the file to save? Is there are way to do it using only repl.it or do you have to use something else and how? Also, I am using python. I also know JavaScript but I just started learning 1 week ago so I am a really bad at it.

Answered by DynamicSquid [earned 5 cycles]
View Answer
Voters
lightningrock
Comments
hotnewtop
DynamicSquid

open the file as open("file_name.txt", "a"), a for append

lightningrock

no i need help so that the file contents are still there after a reload @DynamicSquid

DynamicSquid

@lightningrock yeah, like this:

DynamicSquid

@lightningrock

Don't forget to mark this answer as accepted if it helped!

lightningrock

am i doing something wrong here?
Plz point it out cuz im rly cunfused

@DynamicSquid @DynamicSquid @DynamicSquid @DynamicSquid @DynamicSquid @LightningRock @DynamicSquid @DynamicSquid @DynamicSquid @DynamicSquid @DynamicSquid @DynamicSquid @DynamicSquid @DynamicSquid @DynamicSquid @DynamicSquid @DynamicSquid @DynamicSquid @DynamicSquid @DynamicSquid @DynamicSquid @DynamicSquid @DynamicSquid @DynamicSquid

DynamicSquid

@lightningrock no that's good :)

lightningrock
AnthonyFerr

@DynamicSquid When I open a tab with the console link, the program does not save the user input. The same code works when I'm looking at the backend and run it.

Dashdaber154
Muffinlavania

i can help..

lightningrock
Muffinlavania

@lightningrock this works
f = open('file.txt','a')
f.write("BOOGA BOOGA")
f.close()
Just make the file.txt beforehand, i reloaded and it saved

Muffinlavania

@Muffinlavania of course wait for repl to save the stuff, then reload

Muffinlavania

@lightningrock
https://repl.it/@Muffinlavania/LustrousInconsequentialPlans
The project with file.txt, you will see it has saved and is in there

lightningrock

wait now it works!

Yay!

@Muffinlavania

Muffinlavania

@lightningrock yay gg POG champ