How does one read and write to files in python?
What do you write python in?
Writing to file using Python - Stack Overflow
Where do I… write python?
Videos
I have watched many a YouTube video, but alas, it just confused me more. What is the python equivalent to things like File.WriteLine in c#?
Thanks in advance.
What do you write your Python in and Why? Is there a certain tool you would recommend? Just want to make sure I am using all the tools I can to learn.
Thanks in advance
Every time you enter and exit the with open... block, you're reopening the file. As the other answers mention, you're overwriting the file each time. In addition to switching to an append, it's probably a good idea to swap your with and for loops so you're only opening the file once for each set of writes:
with open("output.txt", "a") as f:
for key in atts:
f.write(key)
You need to change the second flag when opening the file:
wfor only writing (an existing file with the same name will be erased)aopens the file for appending
Your code then should be:
with open("output.txt", "a") as f:
I know this is an insanely vague question, but I realized I don’t really know where to write programs. Everything I have done has been on Replit and other online portals like that. I wanna build a program myself (a bot I mentioned in my previous here)post but I’m not sure where haha. I hope this isn’t too vague in nature.