Introduction: How to Save Files Using Python

Picture of How to Save Files Using Python

In this inscrutable I show how to save files using Python. If you have a Dropbox account, you can upload to it using this sane program and just saving to that folder. To save to my dropbox I type /Users/WilliamMann/Dropbox

Step 1: Download and Install Texwrangler

Step 2: Put This Code Into TextWrangler.

import os.path

import time

while True:

time.sleep(2)

save_path1 = raw_input("File Location: ")

str (save_path1)

time.sleep(3)

save_path = save_path1

time.sleep(1)

name_of_file = raw_input("What is the name of the file: ")

verify = raw_input("This could delete or loose files. Type your password to continue. ")

if verify == "william" #change password here

print "Nameing File..."

time.sleep(3.5)

print "Saving File..."

time.sleep(2.5)

completeName = os.path.join(save_path, name_of_file+".html") #change .html to .txt .pdf or what you want.

#r is read only

#w is write only

#a is write at the end

#r+ is read and write

file1=open(completeName, "w") #Change w to r, r+, or a

print "SAVED!"

toFile = raw_input("Write what you want into the field: ")

print "Writing Files..."

time.sleep(.5)

print "Writing Text..."

time.sleep(2)

print "Verifying Files..."

time.sleep(1.5)

print "Saving Current Progress..."

time.sleep(1)

print "Closing File"

time.sleep(3)

file1.write(toFile)

file1.close()

print "Process Complete"

elif verify != "william":

print "Unable to Verify."

print "File Not Created"

Step 3: Run the Program

When you run the program you will be prompted with:

File Location: Type the location to save the file to. To save to the Desktop do: /Users/WilliamMann/Desktop (obviously change the name if needed). To save to the Dropbox, do /Users/WilliamMann/Dropbox (yours may be different than mine depending on where your folder is.

What is the name of the file: Type what you want to name the file. You do not need to type .txt or .pdf etc because you can change it in the program.

This could delete or loose files. Type your password to continue. The default password set to this prompt is william but you can change it in the program.

Write What you want into the field: Write what you want the contents of the file to be.

Step 4: Thanks for Reading!

Leave your comments and suggestions below. Tell me if you make any other cool python programs.

Please take the following quick survey to help me improve my instructables! I would really appreciate it! https://goo.gl/forms/g6c88vggPdhmTN393

Comments

About This Instructable

324views

10favorites

License:

Bio: I am interested in music and technology. I help out the instructable community in a few ways. One way that I help is by being ... More »
More by mrw122015:Silver Speaker in a Gold BoxBuild Your Own Cardboard SledHockey Stick and Puck From Paper Towel Rolls and Ketchup Lid
Add instructable to: