Product SiteDocumentation Site

10.4. Writing in a file

Let us open a file then we will write some random text into it by using the write() method.

>>> f = open("ircnicks.txt", 'w')
>>> f.write('powerpork\n')
>>> f.write('indrag\n')
>>> f.write('mishti\n')
>>> f.write('sm|CPU')
>>> f.close()

Now read the file we just created

>>> f = open('ircnicks.txt')
>>> s = f.read()
>>> print s
powerpork
indrag
mishti
sm|CPU