newbie - script works in PythonWin - fails from Python

M

marcus.tettmar

Hi,

I have a script that runs fine when I run it from within PythonWin but
causes a WindowsError: Exception when I try to run it from the command
line using python.exe. What is PythonWin doing differently?
 
F

Fredrik Lundh

I have a script that runs fine when I run it from within PythonWin but
causes a WindowsError: Exception when I try to run it from the command
line using python.exe. What is PythonWin doing differently?

is that the entire traceback ?

what is the script doing when you get that error message ?

</F>
 
F

Fuzzyman

Hi,

I have a script that runs fine when I run it from within PythonWin but
causes a WindowsError: Exception when I try to run it from the command
line using python.exe. What is PythonWin doing differently?

Hello Marcus,

Can you post the full exception, and preferably the snippet of code
(with relevant context) that caused it. This will give people a better
chance of being able to help you.

All the best,


Fuzzyman
http://www.voidspace.org.uk/python/index.shtml
 
M

marcus.tettmar

I'm using ctypes and loading a DLL and running a DLL function. As I
say it works perfectly with no errors when I run from PythonWin but
gives the following exception when run from command line.

WindowsError: exception code 0xeedfade

I can use the DLL with no issues in other languages too. It works fine
in VB, C++ and in Python when run from PythonWin but gets an exception
when run from python.exe

PythonWin must be doing something different, but I can't find anything
in the documentation.
 
S

Steven D'Aprano

I'm using ctypes and loading a DLL and running a DLL function. As I
say it works perfectly with no errors when I run from PythonWin but
gives the following exception when run from command line.

WindowsError: exception code 0xeedfade

I find it hard to believe that this is the entire exception traceback.
This is what a traceback looks like:

File "<stdin>", line 1
dosomething wrong(20)
^
SyntaxError: invalid syntax

See how much information is given by the traceback? If I just posted
"SyntaxError: invalid syntax" to the newsgroup with no further
information, what do you think the chances are anyone would guess the
cause of the problem?

So, how about trying again with the complete traceback?
 
M

marcus.tettmar

Hi,

This is all I get:

error 250477278
Traceback (most recent call last):
File "script1.py", line 5, in ?
Inst = lib.Initialize(0)
WindowsError: exception code 0xeedfade

I get this when running python.exe script1.py

** When run from inside PythonWin it runs beautifully and returns with
no errors **

Regardless of what the error actually is it *works* when run from
PythonWin. It fails only when run from the command line. I'm trying
to find out why there is a difference. Clearly both either run a
different interpreter or with different switches. I was hoping someone
knows what the difference is.
 
T

Thomas Heller

Hi,

This is all I get:

error 250477278
Traceback (most recent call last):
File "script1.py", line 5, in ?
Inst = lib.Initialize(0)
WindowsError: exception code 0xeedfade

I get this when running python.exe script1.py

** When run from inside PythonWin it runs beautifully and returns with
no errors **

Regardless of what the error actually is it *works* when run from
PythonWin. It fails only when run from the command line. I'm trying
to find out why there is a difference. Clearly both either run a
different interpreter or with different switches. I was hoping someone
knows what the difference is.

One difference is that PythonWin runs a messageloop. Does the
documentation of the library you call say something about the error code
you get?

Thomas
 
M

marcus.tettmar

Unfortunately not. Is there any doc anywhere that shows how to make
the script run from the command line the same way it does within
PythonWin?
 
S

Steven D'Aprano

Hi,

This is all I get:

error 250477278

What is this line? That doesn't look like part of a Python traceback. I
suppose it is possible that the DLL is printing it before the exception is
raised. Or did you type it yourself?

Traceback (most recent call last):
File "script1.py", line 5, in ?
Inst = lib.Initialize(0)
WindowsError: exception code 0xeedfade

I get this when running python.exe script1.py

You're still making it as hard as possible for anyone to help you. Is it a
secret what DLL you are trying to call? What is "lib"?

Googling on 0xeedfade suggests that it is an internal Delphi error,
possibly an out-of-memory error. Are you calling a Delphi DLL? What does
that exception mean?
 
F

Fredrik Lundh

Thomas said:
One difference is that PythonWin runs a messageloop. Does the
documentation of the library you call say something about the error code
you get?

a quick googling indicates that 0xEEDFADE is usually caused by an
internal unhandled exception in Delphi. maybe there's some Borland-
specific DLL that's not found when the code is running from the con-
sole ?

I suppose you could use process explorer to see if you can figure out
what Borland DLL:s the program is using:

http://www.sysinternals.com/ProcessesAndThreadsUtilities.html

</F>
 
M

marcus.tettmar

Hi,

Sorry, I'm not trying to make things hard! I just can't figure why it
works when run from PythonWin and not from Python - PythonWin MUST load
some extra library.

Anyway, I have finally fixed it by adding import win32com to the top of
the script. Am guessing the DLL uses COM and PythonWin must already
load it.
 
D

Dennis Lee Bieber

Anyway, I have finally fixed it by adding import win32com to the top of
the script. Am guessing the DLL uses COM and PythonWin must already
load it.

<duh> From the help system:

-=-=-=-=-=-=-=-
On Windows, ActivePython also includes PyWin32 -- a suite of Windows
tools developed by Mark Hammond, including Win32 API integration,
support for Python ASP, the PythonCOM system and the Pythonwin IDE.
-=-=-=-=-=-=-=-

On Windows, it is more the other way around... PythonWin is a
demonstrator of what can be done /using/ the Win32API libraries...
--
 
M

marcus.tettmar

Goodness, you're a nice friendly lot aren't you!? I saw that and I
realise that ActivePython COMES with support for Windows. But it
doesn't say that it forces scripts you create with it to load modules
you haven't implicitly imported yourself! It doesn't say that a
script might run in PythonWin but not in the command line python.

************
<duh> From the help system:

-=-=-=-=-=-=-=-
On Windows, ActivePython also includes PyWin32 -- a suite of Windows
tools developed by Mark Hammond, including Win32 API integration,
support for Python ASP, the PythonCOM system and the Pythonwin IDE.
-=-=-=-=-=-=-=-
************
 
D

Dennis Lee Bieber

Goodness, you're a nice friendly lot aren't you!? I saw that and I
realise that ActivePython COMES with support for Windows. But it
doesn't say that it forces scripts you create with it to load modules
you haven't implicitly imported yourself! It doesn't say that a
script might run in PythonWin but not in the command line python.
The key is that PythonWin is NOT loading the modules "for your
script"... It loaded those modules for ITSELF -- the whole GUI of
PythonWin is based on the Win32api; when you ran your script from within
PythonWin, you had ITS environment as part of your global namespace.

That's what I meant by "reverse"; without the Win32api modules,
there is NO PythonWin IDE...

Didn't you wonder about how PythonWin was able to do the pop-up
assistance when you typed something like "win32api."? If you've never
executed an import for a module, and PythonWin gives that help, then
PythonWin had already, at some level, loaded the module for its own use.
Where it is in the namespace I don't really know -- only that some are
in use by PythonWin from the start.

Oh, and even if you do perform an import in the interactive window,
that action, too, makes the module available to all scripts being
edited/run within that session.

--
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,022
Latest member
MaybelleMa

Latest Threads

Top