Oserror: [Errno 20]

Peter Hansen peter at engcorp.com
Mon Apr 3 07:45:02 EDT 2006


k r fry wrote:
> Hi, I am new to this list and also programming with python.
> 
> I have an error: oserror [errno 20] not a directory "katiescint.py"

Please always post complete tracebacks, and without manually reentering 
the data.  In most cases you'll save us and you lots of time and guessing.

> The piece of code causing the problem is:
> [code]
> 
> for subdir in os.listdir(DATADIR):              #loop through list of 
> strings
> 
>      file=FITS.Read(DATADIR+'/'+subdir+'/flux.fits')     #opens 
> flux.fits file and reads

os.listdir() returns a list of all files and directories inside the 
directory specified (DATADIR), so you can't assume that "subdir" is 
always going to be a directory.  Use os.path.isdir() to confirm that it 
is and ignore those items for which that function returns False.

-Peter




More information about the Python-list mailing list