Prev | Index | NextFile Manipulation Examples
>>> # opening a file and reading its contents
... # into a list
...
>>> fav_chess_players = open("fav_chess_players.txt")
>>> fcp = fav_chess_players.readlines()
>>> fcp
['Fischer\n', 'Kasparov\n', 'Tal\n']
>>>
>>> # add a new favourite player to the end of the file
...
>>> fav_chess_players = open("fav_chess_players.txt", "a")
>>> fav_chess_players.write("Leko\n")
>>> fav_chess_players.close()
Files provide a variety of useful methods: read(), seek(), readlines(), write(), writelines(), xreadlines() and more.
See the Python documentation (http://python.org/doc/current/) for more
An Introduction To Python