forked from mwarkentin/Learn-Python-The-Hard-Way
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathex15.py
30 lines (20 loc) · 758 Bytes
/
ex15.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# import argv from the sys module
from sys import argv
# set script and filename variables from the script arguments
script, filename = argv
# open the filename passed in as an argument, and assign the file object to the txt variable
txt = open(filename)
# print a string with the filename
print "Here's your file %r:" % filename
# print the contexts of the txt file object
print txt.read()
txt.close()
# print a string
print "I'll also ask you to type it again:"
# prompt the user for a file name
file_again = raw_input("> ")
# open the file that the user entered, and then assign the file object to the variable txt_again
txt_again = open(file_again)
# print the contents of the txt_again file object
print txt_again.readlines()
txt_again.close()