GMgKe586q6suSQnyqZLlGCooeWM

Pages

Search

Monday, March 21, 2011

Python - File IO

It's simple to write for a file in Python,
>>> hello = open('hello.txt','w+')
>>> data = 'Indonesia is a nice one and what we hope here is like this one'
>>> hello.write(data)
>>> hello.close();

To read a file, use:
>>> hello = open('hello.txt', 'r+')
>>> data = hello.read()         # read all file
>>> data = hello.readlines()    # read all file
>>> data = hello.readline()     # just read one line
Share/Bookmark

No comments:

Post a Comment