If
you want to write program that gives option to a user to type the name of the
specific file than you have to implement know built in function raw_input(). It
would be more useful to ask the user to enter specific file and then perform
some operation on that file. This is very simple procedure and is given below:
filename = raw_input('Enter the file name: ')
fname = open(filename)
count = 0
for line in fname:
if line.startswith('Python '):
count = count + 1
print 'There where' , count , 'subject lines in', fname
Result
of previous code when executed is given below.
Enter
the file name: P-files.txt
There
where 3 subject lines in
Nema komentara:
Objavi komentar