? -, , open(), \n . , , , . ( , , .)
http://docs.python.org/3.1/library/functions.html#open
, yourstring = yourstring.replace('\n', '\r\n') Linux- Windows yourstring = yourstring.replace('\r\n', '\n') Windows Linux-. , , , , , , . (, , , \n \r\n Windows, , .)
, Unicode ( , , , Python , - Unicode), bytes.decode() bytearray.decode(), str.encode(). UTF-8 UTF-16:
newstring = yourbytes.decode('utf-8')
yourbytes = newstring.encode('utf-16')
Unicode, .
str.translate() str.maketrans(), , :
http://docs.python.org/3.1/library/stdtypes.html#str.translate
http://docs.python.org/3.1/library/stdtypes.html#str.maketrans
rot_13 :
import string
rot_13 = str.maketrans({x: chr((ord(x) - ord('A') + 13) % 26 + ord('A') if x.isupper() else ((ord(x) - ord('a') + 13) % 26 + ord('a'))) for x in string.ascii_letters})
rot_13 = str.maketrans('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz', 'NOPQRSTUVWXYZABCDEFGHIJKLMnopqrstuvwxyzabcdefghijklm')
S.translate(rot_13) , rot_13 rot_13 , .