how to have python create a file such as 'neta-inf.txt'. I am trying to self teach the language of python to my self sorry if this is a trivial question
how to have python create a file
Page 1 of 12 Replies - 143 Views - Last Post: 21 February 2013 - 06:40 AM
Replies To: how to have python create a file
#2
Re: how to have python create a file
Posted 21 February 2013 - 02:58 AM
http://docs.python.o...d-writing-files
You could use the 'a' flag instead of 'w' to write to the file without erasing its current contents and still create it if it doesn't exist.
Just look around at the python docs or any of the books and tutorials that are around for free.
Enjoy mate.
Nekroze
file = open('neta-inf.txt', 'w')
You could use the 'a' flag instead of 'w' to write to the file without erasing its current contents and still create it if it doesn't exist.
Just look around at the python docs or any of the books and tutorials that are around for free.
Enjoy mate.
Nekroze
This post has been edited by Nekroze: 21 February 2013 - 02:59 AM
#3
Re: how to have python create a file
Posted 21 February 2013 - 06:40 AM
Just to go a little more indepth so you can save some stuff in a file and then print it out.
#Open the file for writing to it.
strings = open("neta-inf.txt", 'w')
strings.write("man")
strings.write("\n")
strings.write("hey")
strings.write("\n")
strings.write("radio")
strings.write("\n")
#close the file
strings.close()
#Open the file to read from it.
strings = open("neta-inf.txt", 'r')
for line in strings:
print line
#always close a file after use to preserve the integrity of the file contents.
strings.close()
Page 1 of 1
|
|

New Topic/Question
Reply



MultiQuote




|