これは Learn Python the Hard Way の演習 15 ですが、私はPython 3を使用しています。
from sys import argv
script, filename = argv
txt = open(filename)
print ("Here's your file %r:") % filename
print txt.read()
print ("I'll also ask you to type it again:")
file_again = input()
txt_again = open(file_again)
print txt_again.read()
ファイルは ex15.py として保存され、ターミナルから実行すると、最初は ex15.txt が正しく読み取られますが、2 回目に要求するとエラーが発生します。
user@user:~/Desktop/python$ python ex15.py ex15.txt<br>
Here's your file 'ex15.txt':<br>
This is stuff I typed into a file.<br>
It is really cool stuff.<br>
Lots and lots of fun to have in here.<br>
I'll also ask you to type it again:<br>
ex15.txt <b>#now I type this in again, and I get a following error</b><br>
Traceback (most recent call last):<br>
File "ex15.py", line 11, in <<module>module><br>
file_again = input()<br>
File "<<string\>string>", line 1, in <<module>module><br>
NameError: name 'ex15' is not defined
どうしたの?