Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- #MakeFile.py
- #Python 2.7
- #Make a new text file
- #Chris Clarke
- #13.08.2014
- import sys
- filename = raw_input("Enter name of file to create: ")
- try:
- fn = open(filename, "r") #see if file exists
- print "File exists. Choose another name." #don't over-write files!
- fn.close()
- sys.exit(1)
- except IOError:
- pass
- try:
- fh = open(filename, "w")
- all_text = ""
- sent = raw_input ("What to use for end of input (e.g. 'zzz'): ")
- print "Now enter text. To quit, enter", sent, "on a new line. Begin typing!"
- while True:
- line = raw_input()
- if line == sent: break
- all_text += line+"\n"
- fh.write(all_text)
- except IOError:
- print "Error: can't create file!"
- else:
- print "Written content in the file {} successfully.".format(filename)
- fh.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement