| welcome to social.hackers | posts are made by Clocwork and Shadowdrifter | added some new hack diaries + podcasts |

Monday, June 6, 2011

Python Programming Lesson Four. ( beginning strings )

    Today’s lesson will be a short one since we will just be discussing Python’s ability to write a user’s input a text file. This code will do two things, it will take whatever you type and assign a variable to it and then it will print that variable to a text file which you will also choose the name of.

ttw = str(raw_input("Enter the text you would like to write to the file: "))
ftw = str(raw_input("What would you like to name the file: "))

textfile=open(ftw,'w')
textfile.write(ttw)

ttw, and ftw are simply the variables for what you want wrote to the file, and what to name the file. The “w” in textfile means to write. Python has three main ways to interact with text files, write, read, append.

No comments:

Post a Comment