< BACKMake Note | BookmarkCONTINUE >
152015024128143245168232148039199167010047123209178152124239215162146120131232127233152067

linecache

The linecache module allows you to randomly access any line of a text file.

For example, the next lines of code belong to the file c:\ temp\ interface.py.

					
import time, sys
name = raw_input("Enter your name: ")
print "Hi %s, how are you?" % name
feedback = raw_input("What do you want to do now? ")
print "I do not want to do that. Good bye!"
time.sleep(3)
sys.exit()

				

Check the result that is retrieved when the function

linecache.getline(file,linenumber) is called.

					
>>> import linecache
>>> print linecache.getline("c:\ \ temp\ interface.py",4)
feedback = raw_input("What do you want to do now? ")

				


Last updated on 1/30/2002
Python Developer's Handbook, © 2002 Sams Publishing

< BACKMake Note | BookmarkCONTINUE >

© 2002, O'Reilly & Associates, Inc.