Linked Questions
63 questions linked to/from Confused by python file mode "w+"
916 votes
9 answers
879k views
Difference between modes a, a+, w, w+, and r+ in built-in open function
In Python's built-in open function, what is the difference between the modes w, a, w+, a+, and r+? The documentation implies that these all allow writing to the file, and says that they open the files ...
-3 votes
2 answers
497 views
python readline() output nothing [duplicate]
I got nothing back from the command readline(). I am new to python and totally confused now. my_file = open("test.txt", "w+") my_file.write("This is a test") print my_file.readline()
1 vote
1 answer
126 views
Substitute file content in Python [duplicate]
I imagine this is a question asked already twenty thousand times, but I cannot understand why the file is always empty. I want to open a file, remove a string from the whole file and then rewrite the ...
0 votes
1 answer
122 views
Does .write(string) replace all file with the new string or just append it? [duplicate]
The coding that I am using to learn: import requests r = requests.get("http://google.com") f = open("./page.html", "w+") f.write(r.text) So if i understand all right this will create a .html file ...
1 vote
2 answers
91 views
When I try and open/edit a .txt file in python, it deletes whatever is inside of the file. What is doing this? [duplicate]
Very short and simple. I am trying to create a highscore txt document for one of the games I'm making apart of a project. I want it to be able to keep the highest score ever reached in a text document ...
0 votes
1 answer
69 views
Able to write but unable to read file [duplicate]
I am using VSC for writing python scripts to read/write file. I am able to write file using the below code: with open("score_card.txt", mode="w+") as file_data: file_data.write(...
0 votes
0 answers
52 views
can't print contents of text file [duplicate]
def homeScreenArt(): print("-*----------*------------*------*------*-") print("-----*-------------*--------------*------") print("-----&&&&&--&&--&&----&...
0 votes
1 answer
60 views
Writing in a text file wont save users input PYTHON [duplicate]
I am trying to make a stock list display and editor project. I am trying to let users input what product they have and quantity they have in stock but it isnt saving to the txt file. Where am I going ...
0 votes
1 answer
43 views
unpickling in w+b mode in python [duplicate]
i tried to do unpickling using w+b mode. i got the exception EOFError: ran out of input. why is unpickling not possible in w+b mode? w+b mode also offers reading a binary file right then why am i ...
115 votes
6 answers
297k views
Python error message io.UnsupportedOperation: not readable
I have this code: line1 = [] line1.append("xyz ") line1.append("abc") line1.append("mno") file = open("File.txt","w") for i in range(3): file....
22 votes
6 answers
40k views
When to open file in binary mode (b)?
I noticed in the docs they always open a CSV file with ‘wb’. Why the ‘b’? I know b stands for binary mode, but when do you use binary mode (I’d guess CSV file is not binary). If relevant I’m writing ...
7 votes
4 answers
28k views
How can i save a pandas dataframe to csv in overwrite mode?
I want to save pandas dataframe to csv in overwrite mode. I want that whenever the program will run again with any changes then it should save the dataframe to csv and overwrite the already saved csv ...
0 votes
1 answer
9k views
Depickling from a (possibly empty) file
So I'm trying to create a file and read from it even though its empty. So the next time I run the program the file will already exist and there will be data in it. #this should create the file ...
6 votes
1 answer
18k views
What is the difference between rw+ and r+
I stumbled onto this stackoverflow question while doing some file IO: Confused by python file mode "w+" r for reading w for writing r+ opens for reading and writing (cannot truncate ...
3 votes
4 answers
3k views
Issue with writing multiple lines into a file in python
I want to download multiple specific links(images´ urls) into a txt file(or any file where all links can be listed underneath each others). I get them but the code wrtite each link on the top of the ...