Linked Questions

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 ...
user avatar
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') ...
tomas's user avatar
  • 461
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 ...
O.rka's user avatar
  • 30.6k
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 ...
user3341402's user avatar
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 ...
Engy El-kafrawy's user avatar
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 ...
hichris123's user avatar
  • 10.2k
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 ...
user3709398's user avatar
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 ...
aviadm71's user avatar
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+') ...
BonsaiKaya's user avatar
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 ...
Monica Mc Mullan's user avatar
-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 ...
SourD's user avatar
  • 2,889
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 ...
Anoop P Alias's user avatar
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 ...
J. Bridges's user avatar
-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 ...
rharper's user avatar
  • 565
-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 ...
Python_fan's user avatar

15 30 50 per page
1
2 3 4 5
13