Hello,
I have some problem with os exception.
In the traceback info I get only the errno without the description.
for examplem when I write:

import os;
os.listdir("no-exists-dir-name");

I get the exception:

Traceback (most recent call last):
  File "<interactive input>", line 1, in <module>
WindowsError: [Error 3] : 'no-exists-dir-name/*.*'

I findout that [Error 3] in errno is map to the string: 'No such process' (return by os.strerror(3)).

Why I did not get something like:
OSErro: [Error 3] : 'No such process' 'no-exists-dir-name/*.*'

I use ActiveState ActivePython 2.5, but it is also at other version and also at the version from python.org.

Thanks

You aren't getting an error message from Python. You're getting an error message from the OS. It's unlikely that Windows Error 3 has any relationship to errno 3

Jeff

Hi,
I understand this,
BUT why I do not get the Error at the format:
<modul-name> : [Error #] : <description> <added info>
I get only:
<modul-name> : [Error #] : <added info>

How can I know what is the exception cause?

I will give another example:

import os
os.mkdir("a")
shutil.copytree("a","a")

The exception I got:

Traceback (most recent call last):
  File "<interactive input>", line 1, in <module>
  File "D:\Program Files\python\lib\shutil.py", line 110, in copytree
    os.makedirs(dst)
  File "D:\Program Files\python\lib\os.py", line 173, in makedirs
    mkdir(name, mode)
WindowsError: [Error 183] : 'a'

The error description the was except here:
The src and the des are the same 'a'

Why I do not get that info ?

Python is portable across a large umber of Operating Systems, so when you use OS calls, the error returned is specific for the particular OS used and generated by that OS. It would be tough for the developers of Python to cross reference all these different error numbers.

Hi,
Thank for your's replays.
I do not mention before but I run this code under XP.

Jeff wrote: So you'll have to resort to careful testing.

I must do it manual?

Does it happent also at your's machines?

Please try it.

I try it at my friend's machine (XP + ActivePython, don't remember ver #) and the results were as expected, with full detailes.

What the different can be?

Can't say. In the original example,

I findout that [Error 3] in errno is map to the string: 'No such process' (return by os.strerror(3)).

Why I did not get something like:
OSErro: [Error 3] : 'No such process' 'no-exists-dir-name/*.*'

you don't get this result because Windows Error 3 'dir-name *.* does not exist' is *not* the same as errno 3: 'No such process'. Those error numbers are for different systems, and there's no relationship between them.

So if your friend's machine did somehow give you both messages -- it's a bug!

Jeff

You right!
He did not get this message, errno list is not the rught error list map.
But he get some message:
"The file already exists." / "src and des are same"

what you get? same as I ?

:D Apparently, my version of Windows is more helpful than yours!

>>> import os
>>> os.listdir("Fred")

Traceback (most recent call last):
  File "<pyshell#1>", line 1, in -toplevel-
    os.listdir("Fred")
WindowsError: [Errno 3] The system cannot find the path specified: 'Fred/*.*'
>>>

So what the differen !
What can I do?

Ask microsoft will answer with "it's python problem"...

No one have solution?

Well, it's not exactly a problem to be solved, unless it's causing some other problem somewhere else. In which case, we find a workaround.

Which version of Python are you running?

I check all the version list here:
python 2.5
python 2.5.1
ActivePython-2.0.0.201.msi
ActivePython-2.1.3-214.msi
ActivePython-2.3.5-236-win32-ix86.msi
ActivePython-2.5.1.1-win32-x86.msi

Now I use ActivePython-2.5.1.1 with PythonWin 2.5.1 (r251:54863, May 1 2007, 17:47:05) [MSC v.1310 32 bit (Intel)] on win32.

Thanks

Hi, sorry for the late reply. But just for the sake of closing this off...

If I understand you correctly, you want a way to correctly know (and report) the nature of an error that has happened. I think what you want is exception handling.

Try wrapping your os calls with this:

try:
... code ...
except OSError, ( errno, strerror ):
print strerror

Cheers!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.