1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| >>> f = open('test.txt', 'wb')
>>> f.write('\n'.join(["ligne num %i" %i for i in range(50)]))
>>> f.close()
>>>
>>> f = open('test.txt')
>>> f.read().count('\n')
49
>>> dir(f)
['__class__', '__delattr__', '__doc__', '__enter__', '__exit__', '__getattribute__', '__hash__', '__init__', '__iter__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__str__', 'close', 'closed', 'encoding', 'fileno', 'flush', 'isatty', 'mode', 'name', 'newlines', 'next', 'read', 'readinto', 'readline', 'readlines', 'seek', 'softspace', 'tell', 'truncate', 'write', 'writelines', 'xreadlines']
>>> help(f.seek)
>>> f.seek(0)
>>> liste = f.readlines()
>>> len(liste)
50 |
Partager