Oserror: [Errno 20]

k r fry k.r.fry at durham.ac.uk
Mon Apr 3 08:03:18 EDT 2006


Sorry for not copying the whole traceback before, I hop I have done it 
right this time.

I am now getting:

Traceback (most recent call last):
   File "katiescint.py", line 153, in ?
     for subdir in os.path.istdir(DATADIR):              #loop through 
list of strings
AttributeError: 'module' object has no attribute 'istdir'

I did think maybe it was meant to be "listdir" instead of "istdir", but 
that doesn't work either.
Sorry to be a pain.


Peter Hansen wrote:

> 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