Re: python tutorial



steve wrote:
I was just looking at the python tutorial, and I noticed these lines:

http://docs.python.org/tutorial/inputoutput.html#reading-and-writing-files

"Windows makes a distinction between text and binary files;
"the end-of-line characters in text files are automatically altered
"slightly when data is read or written.

I don't see any obvious way to at docs.python.org to get that corrected: Is there some standard procedure?

Steve

It's not clear from your question what you want corrected. Are you saying that the tutorial leaves out some detail? Or are you upset that reading the data gets "automatically altered" data?

If it's the former, just lookup the function in the reference documentation (eg. the chm file in a Windows installation).

The way to control the behavior is with the 'mode' parameter to open(). If mode has a 'b' in it, the file is considered binary, which means no translation is done. If the mode has a 'u' in it, or neither 'b' nor 'u', then some translation is done. The purpose of the translation is to let the program always use \n to mean end of line, for code that'll be portable between the various operating system conventions. Windows typically does text files with \r\n at the end of each line. Some Macs do just a \r, and Unix and Linux use a \n.

One reason a programmer has to be aware of it is that he/she may be reading or writing a file from a different operating environment, for example, a script that'll be uploaded to a web server running a different OS.


.



Relevant Pages

  • Re: General Misc. Questions re VB6
    ... In particular Steve's last post to me served to finally get me past the most frustrating blocks; my sincere thanks to Steve and everyone else who has been so helpfull; I know I can be pretty thick, ... But is there a better way to quickly erase several textboxes without having to explicitly type the txtName.Text="" for each one? ... drop-down shows an interesting collection of grays and 2 colors but not the at least 16 windows colors I would have expected. ... Not sure why you're getting only two colours, unless it's windows screen colours. ...
    (microsoft.public.vb.general.discussion)
  • Re: Studying abroad, devastating weird laptop problem
    ... Translate.google.com may help you with the translation. ... - Normal Mode, Safe Mode with Networking, etc.), but no Safe Mode works ... load but it quickly slows down to a crawl, and takes about a minute to ... After this, Windows Calendar ...
    (microsoft.public.windows.vista.general)
  • Re: Mac advocacy again: Springer changes to Mac
    ... Steve de Mena wrote: ... Macs are more user friendly than other computers ... It also said they'll be running OS X, Windows Vista and Windows XP on ...
    (comp.sys.mac.advocacy)
  • Re: .eml.%%%OECustomProperty and windows mail .
    ... If things are not working well, then you can rename the Windows Mail ... "Steve Cochran" wrote: ... You have to go to the directory where the eml files are. ... CD Local Folders ...
    (microsoft.public.windows.vista.mail)
  • Re: Macs not used in business?
    ... Steve de Mena wrote: ... its traditional Windows server architecture to install a similar ... The company considered upgrading its aging Windows XP terminal server ...
    (comp.sys.mac.advocacy)