rfile.readline()

Dave Angel davea at ieee.org
Sat Aug 28 05:39:53 EDT 2010


sarah wrote:
> i want to know that what this function returns???
>
> and what does this function do??
>
>   
rfile.readline()

No way to tell what the function returns from your subject line.

As for what calling it does, that depends entirely on the object rfile.  
If it's an instance of a class you wrote, you'll have to look up in your 
source code.  If it's an instance of one of the built-in system types, 
or of a class in the standard library, then you can tell by looking up 
that type.

I see standard classes  bz2.BZ2File, codecs.StreamReader, 
distutils.text_file, file, imaplib, mmap, io.IOBase, io.TextIOBase, and 
multifile.   These were from the docs for Python 2.6.

Most of these are probably analogous to file, in which case I can elaborate.

If rfile is an instance of file, perhaps by doing
    rfile = open("myfile.txt", "r")

then  rfile.readline() reads one line from that file, starting at the 
current position, and leaves the file position after that line.  
readline() stops when it reaches a newline (which it may convert, 
depending on the setting of 'rb' versus 'r'), or when it reaches end of 
file.  The trailing newline (if any) is included in the returned string.

That string may be in byte form (Python 2.x), or in unicode (Python 
3.x).  In the latter case, it has been decoded according to parameters 
of the particular open file.

DaveA




More information about the Python-list mailing list