2012/7/24 Marco Beri <marcob...@gmail.com>: > 2012/7/24 Daniele Varrazzo <p...@develer.com> >> >> In windows forse "rstrip('\r\n')" รจ anche meglio, ma non sono sicuro sia >> necessario (forse py converte CRLF -> LF? Non mi ricordo). > > > Secondo me non converte. > > marcob@pc-beruntu:~$ od -c x > 0000000 \r \n > 0000002 > marcob@pc-beruntu:~/tmp$ python > Python 2.7.2+ (default, Oct 4 2011, 20:03:08) > [GCC 4.6.1] on linux2 > Type "help", "copyright", "credits" or "license" for more information. >>>> file("x", "r").read() > '\r\n' >>>> file("x", "rb").read() > '\r\n'
Converte se glielo dite (aka operatore 'U') :D >>> open('foo.txt', 'wb').write("1\n2\r\n3\n") >>> open('foo.txt', 'r').read().split('\n') ['1', '2\r', '3', ''] >>> open('foo.txt', 'rU').read().split('\n') ['1', '2', '3', ''] ref: http://docs.python.org/library/functions.html#open ciao! alberto _______________________________________________ Python mailing list Python@lists.python.it http://lists.python.it/mailman/listinfo/python