YouTip LogoYouTip

File Readline

# Open file fo = open("tutorial.txt", "rw+") print "File name: ", fo.name line = fo.readline() print "Read first line %s" % (line) line = fo.readline(5) print "Read string is: %s" % (line) # Close file fo.close()

Output result of the above example:

File name: tutorial.txt
Read first line 1:www.

Read string is: 2:www

Image 4: Python File Methods Python File Methods

← File ReadlinesPython File Read β†’