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 ariaholic
• 7,340 points
79 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 10, 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 4, 2018 in Python by aayushi
• 750 points
1,757 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 in Python by SA
• 1,030 points
110 views
0 votes
1 answer

What is the difference between Python and IPython?

There are few differences between Python and ...READ MORE

answered Jul 26, 2018 in Python by Priyaj
• 56,900 points
410 views
0 votes
1 answer

What is the difference between re.search and re.match?

The theoritical approach can be this way, re.match is ...READ MORE

answered Aug 10, 2018 in Python by Priyaj
• 56,900 points
934 views
+4 votes
6 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 6 in Python by Neha
• 330 points

edited Jul 8 by Kalgi 283 views
+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 3, 2018 in Python by charlie_brown
• 7,720 points
1,941 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
120 views