vankee
vankee

Reputation: 93

about "from sys import argv "

from sys import argv

script, filename = argv

txt = open(b)

print "Here's your file %r:" % b
print txt.read()

print "Type the filename again:"
file_again = raw_input("> ")

txt_again = open(file_again)

print txt_again.read()

I run it in cmd but it shows that txt=open(b) nameerror:name'b' is not defined..

I have a b.txt file. I don't know what's wrong..thanks!

Upvotes: 0

Views: 2215

Answers (1)

Avinash Raj
Avinash Raj

Reputation: 174706

Since argv contains the list of argument passed, argv[0] contains the script name and argv[1] contains the first argument passed (ie, your filename)

script, filename = argv
txt = open(filename)

Upvotes: 1

Related Questions