[Tutor] oserror [errno 20]
ukc802591034 at btconnect.com
Mon Apr 3 19:57:33 CEST 2006
"k r fry" <k.r.fry at durham.ac.uk> wrote in message
news:443108AC.2000205 at durham.ac.uk...
> 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"
That tells you that the code is finding a file called Katiescint.py
in DATADIR and that youy are trying to treat it as a directory
when it clearly isn't.
But it's better to send the whole stacktrace error message in future
since that tells us *where* the problem lies as well as what it is!
> for subdir in os.listdir(DATADIR): #loop through list of
listdir lists files as well as directories.
> #opens flux.fits file and reads
I'll need to take your word for that.
I assume FITS is a module? and Read is a function within that module?
All caps normally indicates a constant in Python - its only a convention
but a pretty common one. And functions usually start in lowercase
(and classes in uppercase) but again thats a convention and less
Also 'file' is a function (actually an alias for open() ) so using it as a
variable name could cause confusion.
> summation=open(DATADIR+'/'+subdir+'/flux.dat','w') #opens the
> spotbyspot=open(DATADIR+'/'+subdir+'/spotflux.dat','w') #opens the
And here is where you use the file as a directory and cause the error.
Author of the learn to program web tutor
More information about the Tutor