Linked Questions
187 questions linked to/from How do I append to a file?
57
votes
1
answer
176k
views
How to write to a file without overwriting current contents? [duplicate]
with open("games.txt", "w") as text_file:
print(driver.current_url)
text_file.write(driver.current_url + "\n")
I'm using this code right now, but when it writes to the file it overwrites the ...
12
votes
1
answer
33k
views
Append a text to file? [duplicate]
How to check that the file exists?
How to append a text to the file?
I know how to create the file, but in this case, it overwrites all data:
import io
with open('text.txt', 'w', encoding='utf-8') ...
10
votes
1
answer
93k
views
Using "with open() as file" method, how to write more than once? [duplicate]
Usually to write a file, I would do the following:
the_file = open("somefile.txt","wb")
the_file.write("telperion")
but for some reason, iPython (Jupyter) is NOT writing the files. It's pretty ...
5
votes
4
answers
19k
views
Writing to the end of a text file in python 3 [duplicate]
I'm currently working on a bit of code that requires me to keep records of the outcome.
However, at the minute, the code I'm using only overwrites the document, rather than adding on.
What can I write ...
3
votes
2
answers
15k
views
python write to file from dictionary [duplicate]
I'm new with Python and I know that piece of code is very simple and lacks some statements, actually I need to write to file from dictionary. This code runs but only writes the last item in dict to ...
6
votes
2
answers
5k
views
Write to CSV on first empty line [duplicate]
I'm developing an application to write lines to a CSV. However, when I run the application a second time, the line that was already written is overwritten with the new line. How can I make it so that ...
2
votes
2
answers
7k
views
How to avoid overwriting a file in python? [duplicate]
I am trying to make a program that will take the answers of what the user inputted and put it in a text document in Python 2.7. I have the problem of when running the program again, the text document ...
1
vote
4
answers
21k
views
Writing to file using Python [duplicate]
I have a file called output.txt, which I want to write into from a few functions around the code, some of which are recursive.
Problem is, every time I write I need to open the file again and again ...
2
votes
1
answer
5k
views
Write to the last line of a text file? [duplicate]
I am trying to get the program to automatically start at the last line of a text file when I run it and make it write on the last line. My current code is as follows:
with open('textfile.txt', 'a+') ...
1
vote
3
answers
9k
views
Python- how to write to text file without deleting contents [duplicate]
I am new to programming and was wondering if anyone can help me. I have created a program below that enables me to write to the text file. I have a third Column called flower_quantity. I was wondering ...
-2
votes
3
answers
449
views
Writing to a file (python) [duplicate]
if data.find('!add') != -1:
f = open('masters.txt', 'w')
f.writelines(args, '\n')
sck.send('PRIVMSG ' + chan + ' :' + ' added' + " " + args + '\r\n')
f.close()
When I use ...
4
votes
0
answers
6k
views
Append data to a YAML file using Python [duplicate]
I am trying to write a dictionary value to a YAML file.
The dict is:
data_dict = {'BACKENDTYPE' :{ 'BACKENDNAME' : 'BACKENDPATH'}}
The update code is:
with open(backend_config_file,'w')as ...
0
votes
1
answer
3k
views
How can I save to a .txt file without overwriting everything that was already in there? [duplicate]
I'm making what is supposed to be just a very basic OS during my free time. However, I'm trying to make it so that you can have as many users as you want, but every time I make a new user, it deletes ...
-1
votes
2
answers
1k
views
Python overwriting file instead of appending [duplicate]
I'm creating a personal TV show and movie database and I use Python to get the information of the TV shows and movies. I have a file to get information for movies in a folder, which works fine.
I ...
-8
votes
1
answer
2k
views
How to get Python to print primes into a text file? [duplicate]
I coded a Python tool that calculates prime numbers within a given range. Then I decided that copying the numbers from the shell, creating a txt file, and pasting them every single time is a tad ...