Код: Выделить всё
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()
Код: Выделить всё
user@user:~/Desktop/python$ python ex15.py ex15.txt
Here's your file 'ex15.txt':
This is stuff I typed into a file.
It is really cool stuff.
Lots and lots of fun to have in here.
I'll also ask you to type it again:
ex15.txt #now I type this in again, and I get a following error[/b]
Traceback (most recent call last):
File "ex15.py", line 11, in
file_again = input()
File "", line 1, in
NameError: name 'ex15' is not defined
Подробнее здесь: https://stackoverflow.com/questions/129 ... rom-a-file
Мобильная версия