What is the difference between python s file I O system when using w and wb

0 votes
Wondering what the real difference is when writing files from Python. From what I can see if I use wor wb I am getting the same result with text.

While learning python one thing was never clear to me. What exactly is the real difference when using the 'w' and 'wb' parameter. They produce identical results. I thought that saving as a binary file would show only binary values in a hex editor, but it also shows text and then ASCII version of that text.

Can both be toggled when saving text?

P.S: I'm a windows user
Sep 7, 2018 in Python by aryya
• 7,450 points
1,177 views

1 answer to this question.

0 votes
Only in Windows, in the latter case, .write('\n') writes one byte with a value of 10. In the former case, it writes two bytes, with the values 13 and 10.

You can prove this to yourself by looking at the resulting file size, and examining the files in a hex editor.

In POSIX-related operating systems (UNIX, SunOS, MacOS, Linux, etc.), there is no difference between 'w' and 'wb'.
answered Sep 11, 2018 by charlie_brown
• 7,720 points

Related Questions In Python

0 votes
1 answer

What is the difference between list and tuple?

Lists are mutable(values can be changed) whereas ...READ MORE

answered May 5, 2018 in Python by aayushi
• 750 points
6,526 views
+1 vote
2 answers

What is the difference between classes and labels in machine learning?

Classes and Labels both are almost same things ...READ MORE

answered Apr 3, 2019 in Python by SA
• 1,090 points
7,029 views
+5 votes
6 answers

Lowercase in Python

You can simply the built-in function in ...READ MORE

answered Apr 11, 2018 in Python by hemant
• 5,790 points
3,485 views
0 votes
2 answers
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 7, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 4,067 views
0 votes
1 answer
+2 votes
3 answers

How can I play an audio file in the background using Python?

down voteacceptedFor windows: you could use  winsound.SND_ASYNC to play them ...READ MORE

answered Apr 4, 2018 in Python by charlie_brown
• 7,720 points
12,932 views
0 votes
1 answer

When I create and remove files rapidly on windows using python I get WindowsError (Error 5)

Here's the short answer: disable any antivirus or ...READ MORE

answered Aug 31, 2018 in Python by charlie_brown
• 7,720 points
1,669 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP