open('temp bin''rb'read( ' \ \rc\ \ \ndopen('temp bin'' 'read(' \ \nc\ \ndtext mode writeadded \ again dropsalters \ on input the short story to remember here is that you should generally use \ to refer to endline in all your text file contentand you should always open binary data in binary file modes to suppress both end-of-line translations and any unicode encodings file' content generally determines its open modeand file open modes usually process file content exactly as we want keep in mindthoughthat you might also need to use binary file modes for text in special contexts for instancein ' exampleswe'll sometimes open text files in binary mode to avoid possible unicode decoding errorsfor files generated on arbitrary platforms that may have been encoded in arbitrary ways doing so avoids encoding errorsbut also can mean that some text might not work as expected--searches might not always be accurate when applied to such raw textsince the search key must be in bytes string formatted and encoded according to specific and possibly incompatible encoding scheme in ' pyeditwe'll also need to catch unicode exceptions in "grepdirectory file search utilityand we'll go further to allow unicode encodings to be specified for file content across entire trees moreovera script that attempts to translate between different platformsend-of-line character conventions explicitly may need to read text in binary mode to retain the original line-end representation truly present in the filein text modethey would already be translated to \ by the time they reached the script it' also possible to disable or further tailor end-of-line translations in text mode with additional open arguments we will finesse here see the newline argument in open reference documentation for detailsin shortpassing an empty string to this argument also prevents line-end translation but retains other text-mode behavior for this let' turn next to two common use cases for binary data filespacked binary data and random access parsing packed binary data with the struct module by using the letter in the open callyou can open binary datafiles in platform-neutral way and read and write their content with normal file object methods but how do you process binary data once it has been readit will be returned to your script as simple string of bytesmost of which are probably not printable characters if you just need to pass binary data along to another file or programyour work is done--for instancesimply pass the byte string to another file opened in binary mode and if you just need to extract number of bytes from specific positionstring slicing will do the jobyou can even follow up with bitwise operations if you need to to get file tools