and returns the file contents as list of stringslines [with open('the-zen-of-python txt'as flines readlines(count for line in linescount + print( 'line {count}{line}'outputline beautiful is better than ugly line explicit is better than implicit line simple is better than complex the file object attributes once file is opened and you have one file objectyou can get various information related to that file here is list of all attributes related to file objectattribute file closed file mode file name file softspace description returns true if file is closedfalse otherwise returns access mode with which file was opened returns name of the file returns false if space explicitly required with printtrue otherwise example open file fo open("foo txt""wb"print "name of the file"fo name print "closed or not "fo closed print "opening mode "fo mode print "softspace flag "fo softspace