[Q] File Object -- function 'read'

jackyci jackyci at sinamail.com
Thu Jul 19 12:22:20 EDT 2001


Hi 

There is a TEXT file named 'test.txt'.
--------test.txt-------
This is a test.\n
test\n
test\n
-----------------------
In Windows. "\n" equal "\x0d\x0a"
But in function "read" of File Object, "\x0d\x0a" equal 1 byte.

file = open('test.txt')
str = file.read(22)    # I want to read the first two line

# but str = This is a test\ntest\nte

How to solve the problem ?

Greetings
==================================================================
新浪網.免費 50MB 電子信箱  http://www.sinamail.com
夏天到,準備打包渡假去!
http://bonus.sina.com.tw/adevents/alico/






More information about the Python-list mailing list