[Tutor] oserror [errno 20]

Ewald Ertl ewald.ertl at hartter.com
Mon Apr 3 15:11:55 CEST 2006


k r fry wrote:
> Hi, I am new to this list, and also to Python.
> I am trying to get Python to loop through the directory DATADIR which 
> contains the data I want to read.  I get an error:  "oserror [errno 20] 
> : Not a directory: "Katiescint.py"
> The section of code is shown below:
> for subdir in os.listdir(DATADIR):              #loop through list of 

os.listdir() lists the content of the directory referenced by DATADIR.
If regular files are in this directory, these are also listed.
You have to check, if subdir is really a directory before using this any

> strings
>      file=FITS.Read(DATADIR+'/'+subdir+'/flux.fits')     #opens 
> flux.fits file and reads
>      summation=open(DATADIR+'/'+subdir+'/flux.dat','w')  #opens the 
> summation results file for writing to
>      spotbyspot=open(DATADIR+'/'+subdir+'/spotflux.dat','w') #opens the 
> spot-by-spot file for writing to
>      output=''
>      print'\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n'+sys.argv[1]+' 
> '+subdir+'\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n'
> I would be very grateful if anyone could help me.  Thanks!
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor

HTH Ewald

More information about the Tutor mailing list