473,387 Members | 1,578 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Oserror: [Errno 20]

Hi, I am new to this list and also programming with python.

I have an error: oserror [errno 20] not a directory "katiescint.py"

The piece of code causing the problem is:
Expand|Select|Wrap|Line Numbers
  1.  
  2. for subdir in os.listdir(DATADIR):              #loop through list of
  3. strings
  4.  
  5. file=FITS.Read(DATADIR+'/'+subdir+'/flux.fits')     #opens
  6. flux.fits file and reads
  7.  
  8. summation=open(DATADIR+'/'+subdir+'/flux.dat','w')  #opens the
  9. summation results file for writing to
  10.  
  11. spotbyspot=open(DATADIR+'/'+subdir+'/spotflux.dat','w') #opens the
  12. spot-by-spot file for writing to
  13.  
  14. output=''
  15. print'\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n'+sys.argv[1]+'
  16. '+subdir+'\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n'
  17.  
  18.  
The first line is the one with the error. Can anyone help?

Thanks!
Apr 3 '06 #1
10 5752
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

Apr 3 '06 #2
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

Apr 3 '06 #3
k r fry enlightened us with:
I did think maybe it was meant to be "listdir" instead of "istdir",
but that doesn't work either.


And again you don't tell us in what way it doesn't work.

Think about what you post from our point of view. Then re-read it, and
think about it again. Only if you're sure that we'll be able to fully
understand it, hit the 'send' button. That will save us a lot of
guessting and asking, and will also get you your answer a lot faster.

Sybren
--
The problem with the world is stupidity. Not saying there should be a
capital punishment for stupidity, but why don't we just take the
safety labels off of everything and let the problem solve itself?
Frank Zappa
Apr 3 '06 #4
Again, I apologise. Not knowing much about Python means that I don't
know what needs to be provided. I meant it doesn't work in the same way
that "istdir" didn't work.

Here is what I have coded:

for subdir in os.path.istdir(DATADIR): #loop through list
of 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 '

And here is what I get when I try to run it:

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'

Here is trying with listdir:

for subdir in os.path.listdir(DATADIR): #loop through list
of strings

and here is what I get:

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


Sybren Stuvel wrote:
k r fry enlightened us with:
I did think maybe it was meant to be "listdir" instead of "istdir",
but that doesn't work either.

And again you don't tell us in what way it doesn't work.

Think about what you post from our point of view. Then re-read it, and
think about it again. Only if you're sure that we'll be able to fully
understand it, hit the 'send' button. That will save us a lot of
guessting and asking, and will also get you your answer a lot faster.

Sybren

Apr 3 '06 #5
k r fry enlightened us with:
Traceback (most recent call last):
File "katiescint.py", line 153, in ?
for subdir in os.path.listdir(DATADIR): #loop through
list of strings
AttributeError: 'module' object has no attribute 'listdir'


But why do you use that function then? listdir is in the module os,
not in os.path.

Sybren
--
The problem with the world is stupidity. Not saying there should be a
capital punishment for stupidity, but why don't we just take the
safety labels off of everything and let the problem solve itself?
Frank Zappa
Apr 3 '06 #6
I think that if you go back and look at the original reply, he spelled
it "isdir"...;)

--Ben
k r fry wrote:
Again, I apologise. Not knowing much about Python means that I don't
know what needs to be provided. I meant it doesn't work in the same way
that "istdir" didn't work.

Here is what I have coded:

for subdir in os.path.istdir(DATADIR): #loop through list
of 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 '

And here is what I get when I try to run it:

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'

Here is trying with listdir:

for subdir in os.path.listdir(DATADIR): #loop through list
of strings

and here is what I get:

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


Sybren Stuvel wrote:
k r fry enlightened us with:
I did think maybe it was meant to be "listdir" instead of "istdir",
but that doesn't work either.


And again you don't tell us in what way it doesn't work.

Think about what you post from our point of view. Then re-read it, and
think about it again. Only if you're sure that we'll be able to fully
understand it, hit the 'send' button. That will save us a lot of
guessting and asking, and will also get you your answer a lot faster.

Sybren

Apr 3 '06 #7
Thank you very much! *embarassed*.

:-)

Ben Thul wrote:
I think that if you go back and look at the original reply, he spelled
it "isdir"...;)

--Ben
k r fry wrote:
Again, I apologise. Not knowing much about Python means that I don't
know what needs to be provided. I meant it doesn't work in the same
way that "istdir" didn't work.

Here is what I have coded:

for subdir in os.path.istdir(DATADIR): #loop through list
of 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 '

And here is what I get when I try to run it:

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'

Here is trying with listdir:

for subdir in os.path.listdir(DATADIR): #loop through
list of strings

and here is what I get:

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


Sybren Stuvel wrote:
k r fry enlightened us with:

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


And again you don't tell us in what way it doesn't work.

Think about what you post from our point of view. Then re-read it, and
think about it again. Only if you're sure that we'll be able to fully
understand it, hit the 'send' button. That will save us a lot of
guessting and asking, and will also get you your answer a lot faster.

Sybren

Apr 3 '06 #8
k r fry wrote:
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.


You'll get the hang of it... :-)

There are two functions required here: os.listdir(), and
os.path.isdir(). The first one is the correct one for the purpose, as
you originally used it. The second one (which I suppose someone with a
German background might try to spell "istdir" ;-) ) is to test whether a
given path "is [a] dir[ectory]".

If you read the documentation on those two functions, and experiment at
the interactive prompt, you'll shortly notice that os.listdir() returns
only the names of the items in the directory, not the full paths.
os.path.isdir(), on the other hand, requires a full path (since of
course it can't know what directory you looked in with os.listdir), so
you'll have to join the names together before testing them, something
like this (and I'll rely on you to actually *read the docs* and
*experiment at the interactive prompt* this time, instead of giving up
so quickly and asking for help again when you could figure this out
yourself with a little more effort):

for name in os.listdir(DATADIR):
path = os.path.join(DATADIR, name)
if os.path.isdir(path):
filename = os.path.join(path, 'flux.fits')
data = FITS.Read(filename)
# etc....

-Peter

Apr 3 '06 #9
Thank you very much! I really appreciate the help. :)
Apr 3 '06 #10
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"
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.


I'd guess you might want to go with something like:

for root, dirs, files in os.walk(DATADIR):
if 'flux.fits' in files:
file = FITS.Read(os.path.join(root, 'flux.fits'))

read up on:
os.path.join
and
os.walk

The previous code will do lots of recursive walking in a deeply nested
directory structure. If you only want to look at single-level subdirs,
you could either do:

root, dirs, files = iter(os.walk(DATADIR)).next()
for subdir in dirs:
file = FITS.Read(os.path.join(root, subdir, 'flux.fits'))

or:
for root, dirs, files in os.walk(DATADIR):
if 'flux.fits' in files:
file = FITS.Read(os.path.join(root, 'flux.fits'))
if root != DATADIR:
del dirs[:] # Stop recursing after the first descent)

depending on whether you know 'flux.fits' should be there or
you only want to work on subdirs where it is in the directory.

-Scott David Daniels
sc***********@acm.org
Apr 3 '06 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: bmgz | last post by:
I am have made a simple script that moves all desktop clutter (ie files that are not *.lnk) to a specified folder eg. c:\myhome\mydocs\desktopdebris\2003-12-16 ...
0
by: John J. Lee | last post by:
Today, I wanted to do something like this: def nr_files(dirName) try: return len(os.listdir(dirName)) except OSError, e: if e.errno == errno.ENOENT: return 0 else: raise
1
by: Mark Harrison | last post by:
Can somebody loan me a clue as to how to check the errno on an OSError, as described below? try: os.makedirs(d) except OSError: # if errno == 17 then silently ignore the error because the #...
3
by: Scott Whitney | last post by:
oldName=/backup/backups/data/WWW_httpd.conf_backups/20050204.httpd.conf newName=/backup_old/data/WWW_httpd.conf_backups/20050204.httpd.conf os.rename(oldName,newName) gives: OSError: ...
11
by: Alec Wysoker | last post by:
Using Python 2.3.5 on Windows XP, I occasionally get OSError: Permission denied when calling os.remove(). This can occur with a file that is not used by any other process on the machine, and is...
0
by: Joram Agten | last post by:
Please put me in CC When running the following program I get frequent errors like this one Exception in thread Thread-4: Traceback (most recent call last): File...
4
by: David Hirschfield | last post by:
I know this should be obvious, but how does one raise a specific type of OSError? When I attempt to perform a file operation on a non-existent file, I get an OSError: , but what if I want to raise...
0
by: robert | last post by:
e.g. open/os module functions (os.path.getmtime...) and win32api/win32file functions fail on long paths (>~255 chars) even the '\\?\' trick from...
2
by: Michael George Lerner | last post by:
Hi, (Python 2.5, OS X 10.4.10) I have a program called pdb2pqr on my system. It is installed so that "pdb2pqr" is in my path and looks like: #\!/bin/zsh -f /sw/share/pdb2pqr/pdb2pqr.py "$@"...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.