[Tutor] Opening files - Newbie Question
DavidCraig@PIA.CA.GOV
DavidCraig@PIA.CA.GOV
Tue, 17 Jul 2001 13:27:37 -0700
Example from Wes Chun's 'Core Python Programming' page 38:
# Open files to window to read
filename = raw_input('Enter file name: ')
file = open(filename, 'r')
allLines = file.readlines()
file.close()
for eachLine in allLines:
print eachLine
When I run the file and enter a text file to be read I get:
Python 2.1 (#15, Apr 16 2001, 18:25:49) [MSC 32 bit (Intel)] on win32
Type "copyright", "credits" or "license" for more information.
IDLE 0.8 -- press F1 for help
>>>
Enter file name: bruce
Traceback (most recent call last):
File "C:/Python21/Practice/File_open.py", line 4, in ?
file = open(filename, 'r')
IOError: [Errno 2] No such file or directory: 'bruce'
What am I missing? I have tried to input the exact path. Must the file be
a text file to be read?
Thanks for any help.
D. H. Craig, CSM