file is saved as ex15.py, and when I run it from terminal it reads ex15.txt correctly first time, but when I request it second time, I get an error

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

for python 3 you would need to use print() function instead of print statement and str.format() instead of % => you are not using python 3, check the default interpreter for .py files of your operating system
–
AprillionOct 18 '12 at 22:25

Agree on print(), but you can still use the % operator on strings in CPython 3.x. For dual version code, using % can be a good thing. Also pylint checks it well for type issues.
–
user1277476Oct 18 '12 at 23:10

Most likely Python 2 is the default on your system, but you can make your script always use Python 3 by adding this as the first line of your script (if you're running it directly, like ./myscript.py):

#!/usr/bin/env python3

Or running it explicitly with Python 3:

python3 myscript.py

One more note: You should really close the file when you're done with it. You can either do this explicitly: