Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from sys import argv
- script, filename = argv
- txt = open(filename)
- print "Here's your file %r:" % filename
- print txt.read()
- txt.close()
- print "Type the filename again:"
- file_again = raw_input("> ")
- txt_again = open(file_again)
- print txt_again.read()
- txt_again.close()
- ##PYTHON SHELL
- ## >>> import sys
- ## >>> sys.argv=['','sample.txt']
- ## >>> execfile('ex15.py')
- # extra credit
- # Get rid of the part from line 10-15 where you use raw_input and try the script then.
- # Use only raw_input and try the script that way. Think of why one way of getting the filename would be better than another.
- # Run pydoc file and scroll down until you see the read() command (method/function). See all the other ones you can use? Skip the ones that have __ (two underscores) in front because those are junk. Try some of the other commands.
- # Startup python again and use open from the prompt. Notice how you can open files and run read on them right there?
- # Have your script also do a close() on the txt and txt_again variables. It's important to close files when you are done with them.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement