[Tutor] Opening files - Newbie Question

Sheila King sheila@thinkspot.net
Tue, 17 Jul 2001 13:37:48 -0700


The file doesn't have to be a text file to be opened. However, sometimes
on the Windows operating system, the operating system hides the file
extensions on the file names.

Are you sure that your file is named exactly "bruce" ?
What application did you use to create the file name "bruce"? If you
used Notepad, it probably saved the file as "bruce.txt", or if you used
WordPad or MS Word, it probably saved the file as "bruce.doc".

Which Windows operating system are you running? Win98? WinNT? Win2000? I
think that the key is to set your computer so that it is showing all the
file extensions on your filenames, so that you can see for certain what
the exact name of your "bruce" file is.

Alternatively, you could get Python to list the filenames for all the
files in the directory.

Ah, something else I thought of...
You need to type the full path to the file "bruce". Is it in the same
directory as your script? If not, you must type the full path.

When you are prompted to enter the file name, you need to enter
something like:

C:\path\to\file\bruce.ext

HTH

--
Sheila King
http://www.thinkspot.net/sheila/
http://www.k12groups.org/


On Tue, 17 Jul 2001 13:27:37 -0700, DavidCraig@PIA.CA.GOV  wrote about
[Tutor] Opening files - Newbie Question:

: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
:
:
:
:_______________________________________________
:Tutor maillist  -  Tutor@python.org
:http://mail.python.org/mailman/listinfo/tutor