Howto access a enumeration in a COM TypeLib
Hello alltogether, I hope somebody can help me in that case. I bet I have overseen s.th.. I have a VC++ IDispatch Com-Server (ATL) and include for error handling issues a enumeration in the IDL-File. [...] enum PROG_ERROR { P_OK = 0, P_ERR_01 = 1, P_ERR_02 = 2, ... } typedef enum PROG_ERROR PROG_ERROR_T; [...] I can acess the COM object using : obj = win32com.client.Dispatch("...") and can Load the TypeLib: lib = pythonwin.LoadTypeLib("...") and see the enumeration in the OLE-Browser of Windows, but don't know how to access the enum in Python. Any help and hints are very welcome. Regards Alexander PS.: I use the actual version of ActivePython 2.4. -- http://mail.python.org/mailman/listinfo/python-list
Re: Howto access a enumeration in a COM TypeLib
Thanks, thats it. Konstantin Veretennicov schrieb: import myserver print myserver.constants. P_OK > 0 > > Maybe you can access constants without makepy, I don't know. > > - kv -- http://mail.python.org/mailman/listinfo/python-list
COM makepy problem
Hello together, My system: ActivePython 2.4.1 Windows XP I write a COM Server in VC++ 6.0 using ATL. So far so good. While I develop I got sometimes strange behaviour with makepy utility. Today again. :-( What I do on the python (COM client) side. 1) Register COM server 2) Use COM makepy utility 3) Create com client object using win32com.client.Dispatch(...) The generated file in c:\python24\lib\site-packages\win32com\gen_py\{...}\I.py seem not work corectly. From the traceback, when i do myObj = win32com.client.Dispatch("") -- [...] __import__("win32com.gen_py." + dir_name + "." + child) File "c:\Python24\lib\site-packages\win32com\gen_py\D0BC1B38-B4AC-480A-86B0-81 DA572765CDx0x1x0\IDssInterface.py", line 125 IDssInterface_vtables_ = [dispatch_ = 1 ^ SyntaxError: invalid syntax file IDssInterface.py (starting at line 123) [...] LCID = 0x0 IDssInterface_vtables_dispatch_ = 1 IDssInterface_vtables_ = [ [...] Now I change the file IDssInterface.py by hand to: -- [...] LCID = 0x0 IDssInterface_vtables_dispatch_ = 1 IDssInterface_vtables_ = [ [...] and everything works fine !!! Does anybody have a suggestion/idea/hint on that ??? Regards Alexander -- http://mail.python.org/mailman/listinfo/python-list
Re: COM makepy problem
James Kew schrieb: > "Alexander Eisenhuth" <[EMAIL PROTECTED]> wrote in message > news:[EMAIL PROTECTED] >>ActivePython 2.4.1 >>Windows XP >> >>I write a COM Server in VC++ 6.0 using ATL. So far so good. While I >>develop I got sometimes strange behaviour with makepy utility. Today >>again. :-( >> >>SyntaxError: invalid syntax > > I've had the same problems; this pywin32 bug describes it: > http://sourceforge.net/tracker/index.php?func=detail&aid=1166627&group_id=78018&atid=551954 > > I've found no way to avoid it except by downgrading to Python 2.4. > > James > > Do you know, where win32com looks for the COM-server class description (that is generated wrong?) Regards Alexander -- http://mail.python.org/mailman/listinfo/python-list
win32 COM and data types / direction
Hello everybody, i wonder how the win32 COM extension handles different C-int types (short, int, long). Another question for me is weather the "out-direction" of parameter is supported "out of the box" ? To clarify look at the methode "FunWithTwoInts" -- #SimpleCOMServer.py - A sample COM server - almost as small as they come! # # We expose a single method in a Python COM object class PythonUtilities: _public_methods_ = [ 'FunWithTwoInts' ] _reg_progid_ = "PythonDemo.Utilities" # NEVER copy the following ID! # Use "print pythoncom.CreateGuid( )" to make a new one _reg_clsid_ = "{40CEA5F8-4D4C-4655-BD8B-0E7B6A26B556}" def FunWithTwoInts(self, inShort, inInt, outSum): print "got as short:%d as int:%d sum:%d" % (inShort, inInt, outSum) outSum = inShort + inInt # Add code so that when this script is run by # Python.exe, it self-registers if __name__=='__main_ _': print "Registering COM server..." import win32com.server.register win32com.server.register.UseCommandLine(PythonUtilities) -- Does anybody have experiences in this ? Any help/hints are very welcome. Alexander -- http://mail.python.org/mailman/listinfo/python-list
Nice documentation Python / SWIG / C++
Hi alltogether, I found a nice and useful article for extenting python with C++ using SWIG. It describe from the scratch especially for Windows. Maybe this can be included somewhere on www.python.org. Here is the link: http://www.geocities.com/foetsch/python/extending_python.htm Alexander -- http://mail.python.org/mailman/listinfo/python-list
Howto debug c++ (SWIG) extension under Windows
Hi alltogether, I use ActivePython 2.4.1 , also the debug part from http://ftp.activestate.com/ActivePython/etc/ and VC 6.0 unter Windows XP. I can't figure out howto debug my c++ extension. If i compile it as release version, I've of course no chance to set a breakpoint. If I compile as debug I get the Error-window: ... missing MSVCR71D.dll ... when I try to start or debug my application. Now I've only ;-) two questions: 1) Is it possible to debug a C++ extension in that environment anyhow ? 2) How do I have to setup the development environment in that I can debug ? Thank you in advance for your ideas, links, help, hints or whatever ... Regards Alexander -- http://mail.python.org/mailman/listinfo/python-list
Re: Howto debug c++ (SWIG) extension under Windows
Miki Tebeka schrieb: Hello Alexander, I can't figure out howto debug my c++ extension. If i compile it as release version, I've of course no chance to set a breakpoint. This is not true. You *can* set breakpoints in release mode, make sure to add debug information to your release build so you'll be able to see the sources. There are several cases (such as inlined functions) that you *can't* set breakpoint to. Don't work because of my MSVCR71D.dll problem. It seems, that if I include DEBUG informations in my project, there is a reference to that (debug) DLL. If I > compile as debug I get the Error-window: ... missing MSVCR71D.dll ... Just copy it (and msvcp71d.dll) from your c:\windows\system32 (or wherever your windows is installed) to the "Debug" library (or to the Python install library). I don't have the dll MSVCR71D.dll on my system path. What I'm a bit confused about is, that I can't even start python_d (installed by ActiveState DEBUG extension to ActivePython). It requires also the DLL. Does anybody know, where to get that DLL ? Regards Alexander -- http://mail.python.org/mailman/listinfo/python-list
dynamic creation of global Identifier
Hello alltogether, I've a little problem in creating a new identifier in the global namespace. The following code creates a as local var in the namespace of init() class A: def __init__(self, v): print "ctr of", self.__class__, "with", v self._v = v def init(): newIdentifier = ["a", "b"] param = [1,2] for newId, par in zip(newIdentifier, param): exec "global %s" % newId exec "%s = A(par)" % newId init() print a, b but why doesent exec "global ... create a identifier in the global namespace. The next thing I want to do is to create a identifier in a packages namespace anyhow from where init() is called. How can I (or can I not) access from within a function the namespace of the "package" where it is defined? Thanks a lot Alexander -- http://mail.python.org/mailman/listinfo/python-list
Looking for assignement operator
Hello, is there a assignement operator, that i can overwrite? class MyInt: def __init__(self, val): assert(isinstance(val, int)) self._val = val a = MyInt(10) # Here i need to overwrite the assignement operator a = 12 Thanks Alexander -- http://mail.python.org/mailman/listinfo/python-list
Re: Looking for assignement operator
Wow, thanks a lot for your quick answers. That assignement is no operator, but a statemant is a pity, but indeed I came foward with overwritten methods for numeric types Regards Alexander -- http://mail.python.org/mailman/listinfo/python-list
Heap cleanup in python extension
Hello Together, Shortly what I'm doing: - Extending python with boost.pthon extension - Using python C-Api for datatypes in the extension - extension has a thread (that can be stopped/started) - thread started: extension updates a dict (given as parameter to the extension) every 20 ms - the dict looks like: {int:{int:[float,float,float] int:[float,float,float], ...}} Now my question: I create the dict every 20 ms on the heap in the following way: -- static PyObject* createPTDict() { static int aNumIter = 0; PyObject* nRetDictPy = PyDict_New(); // dicto to return PyObject* nToolIdPy = PyInt_FromLong(1234567); PyObject* nLedDict = PyDict_New(); // dict containing 5 key,values for (int aLedNum=0; aLedNum < 5; aLedNum++) { PyObject* aLedNumPy = PyInt_FromLong(aLedNum); PyObject* aLedList = PyList_New(0); for ( int aXYZ=0; aXYZ < 3; aXYZ++) { PyObject* aLedPosXYZ = PyFloat_FromDouble(1.0); PyList_Append(aLedList, aLedPosXYZ); } PyDict_SetItem(nLedDict, aLedNumPy, aLedList); } PyDict_SetItem(nRetDictPy, nToolIdPy, nLedDict); aNumIter ++; return nRetDictPy; } -- I give it to python with: -- PyObject *aKey, *aValue; int aPos = 0; PyObject* aNewToolDict = createPTDict(); PyDict_Next(aNewToolDict, &aPos, &aKey, &aValue); // DictInPython passed prior to extension PyDict_SetItem(, aKey, aValue); -- And now, what would be a proper way to cleanup the heap? 1) Does PyDict_Clear(aNewToolDict) also decrement the ref counting for the containing list, int, ... PyObjects? 2) Do I need to Py_CLEAR( PyObject *o) for every created PyObject? Thanks a lot for every answer/hint. Regards Alexander -- http://mail.python.org/mailman/listinfo/python-list
Memory leak in PyQt application
Hello alltogether, My System: Python 2.5.1 Boost.Python Qt 4.2.2 SIP 4.6 PyQt 4.2 WinXp I've a memory leak in a PyQt application and no idea how to find it. What happens in the application ? From QWindow a QDialog is called on a button "pressed()" signal, that instantiate a QThread and waits for it. If the thread has finished, the QDialog closes. I've stipped down everything that nothing more happens (to me obviously). Boost.Python is used to wrap a C++ Lib (used in the thread). Every time memory usage increases for ~70 KB. Sometimes the application crash on closing QWindow. (QtCore.dll) - One thing I ask me is weather garbage collection is done in the PyQt main loop? What hints do you have to find the leak? Help is very very welcome Regards Alexander -- http://mail.python.org/mailman/listinfo/python-list
PyQt: Is signal / slot really working across threads?
Hello pyqt users, i tried to use signal / slot across threads. With the following example I want to emit a signal when the thread loop is entered. The connected slot is never called. Why? Any help is very welcome ... Alexander import time import sys import PyQt4 from PyQt4.QtCore import (QObject, QThread) SIGNAL = PyQt4.QtCore.SIGNAL class CancelableQtThread_(QThread): def __init__(self): QThread.__init__(self) self.sigStarted = SIGNAL("sigStarted()") def run(self): print "Enter thread" self.emit(self.sigStarted) time.sleep(0.1) print "Leave thread" class TestSigSlot(QObject): def __init__(self): QObject.__init__(self) self._thread = CancelableQtThread_() self.connect(self._thread, self._thread.sigStarted, self.Called) self._thread.start() time.sleep(1.0) def Called(self): print "Called !" if __name__ == "__main__": obj = TestSigSlot() -- http://mail.python.org/mailman/listinfo/python-list
Re: PyQt: Is signal / slot really working across threads?
Ok, thanks. Phil Thompson schrieb: > On Tuesday 29 May 2007 11:58 am, Alexander Eisenhuth wrote: >> Hello pyqt users, >> >> i tried to use signal / slot across threads. With the following example I >> want to emit a signal when the thread loop is entered. The connected slot >> is never called. Why? >> >> Any help is very welcome ... >> >> Alexander >> >> import time >> import sys >> import PyQt4 >> from PyQt4.QtCore import (QObject, QThread) >> SIGNAL = PyQt4.QtCore.SIGNAL >> >> class CancelableQtThread_(QThread): >> >> def __init__(self): >> QThread.__init__(self) >> self.sigStarted = SIGNAL("sigStarted()") >> >> def run(self): >> print "Enter thread" >> self.emit(self.sigStarted) >> time.sleep(0.1) >> print "Leave thread" >> >> class TestSigSlot(QObject): >> >> def __init__(self): >> QObject.__init__(self) >> self._thread = CancelableQtThread_() >> self.connect(self._thread, self._thread.sigStarted, self.Called) >> self._thread.start() >> >> time.sleep(1.0) >> >> def Called(self): >> print "Called !" >> >> if __name__ == "__main__": >> obj = TestSigSlot() > > Signals across threads are implemented using the event loop. You don't have > an > event loop running in your main thread - you don't even have a > QCoreApplication instance. > > Phil -- http://mail.python.org/mailman/listinfo/python-list
Anyone else has seen "forrtl: error (200) ..."
Hello, Ctrl+C is not passed to the interpreter (i guess it) while I'm executing a script. Instead i get: forrtl: error (200): program aborting due to control-C event If I start python in interactive mode Ctrl+C is passed: bash-3.2$ python Python 2.5 (r25:51908, Sep 19 2006, 09:52:17) [MSC v.1310 32 bit (Intel)] on win 32 Type "help", "copyright", "credits" or "license" for more information. >>> raw_input() Traceback (most recent call last): File "", line 1, in KeyboardInterrupt >>> Any idea ? Thanks Alexander -- http://mail.python.org/mailman/listinfo/python-list
Re: Anyone else has seen "forrtl: error (200) ..."
Jason schrieb: > Forrtl indicates that your script is running a Fortran library or > program. Remember that Python exceptions only apply during Python. > If a Fortran DLL performs a divide-by-zero error, or accesses invalid > memory, it will kill the interpreter instead of throwing a Python > exception. With Compaq Visual Fortran, the Fortran library calls can > kill your entire program if a function receives an invalid value. > (Try raising a negative real number to a fractional exponent, for > example.) > > I'd guess that the Fortran code is intercepting the CTRL-C signal and > killing the running script. > > Without knowing anything about your script and the library calls it > makes, I can't give you much advice. There may be little that you can > do, especially if you don't have the Fortran source code in question > and/or can't recompile it. Maybe someone with some Fortran/Python > experience can assist you. > > --Jason > Thanks for that hint. Indeed a extension I'm using in my script uses matlab, and matlab uses (I'm quite sure) fortran. But does that mean, if a fortran dll is loaded, a underlying software layer passes Ctrl+C to the fortran dll instead to python? (I can reproduce that in doing a ctrl+c while my script is currently at time.sleep(10) Thanks, Alexander -- http://mail.python.org/mailman/listinfo/python-list
Re: PEP 8 style enforcing program
[EMAIL PROTECTED] schrieb: > Some recent posts about Python programming style got me thinking. > Since we have the PEP 8 which gives some guidelines about the style to > be used, do we have any program that can check for violations of these > guidelines within the source code? I understand that there are a lot > of code beautifiers out there, but i haven't seen one specially > tailored for Python... Is there even a desire in Python community for > a program like this (by Python community I mean the people in this > group:) ) ? I think it would be a nice little project for practice and > I'd like to do it, but if there is already something like this then I > can probably spend my time on something more productive. So, I'd like > to hear your opinion on this... > There is one thing that I don't understand about PEP 8 - why is using > spaces considered more desirable than using tabs for indentation? > Pylint is one of them (http://www.logilab.org/857) With spaces you get always the same len of the line, where tabs can use 2,4,8 spaces, dependingt on the settings of the IDE Alexander -- http://mail.python.org/mailman/listinfo/python-list
What does r"""any text""" mean ?
... as you can find in os.py at line 1 ? Regards Alexander -- http://mail.python.org/mailman/listinfo/python-list
Re: Class design (information hiding)
Bruno Desthuilliers schrieb: > Nope. It's either 'interface' (no leading underscore), 'implementation' > (single leading underscore), 'implementation with some protection > against accidental overriding' (two leading underscores). What do you mean with 'implementation'? What does it express? -- http://mail.python.org/mailman/listinfo/python-list
Class design (information hiding)
Hi all, I'm wodering how the information hiding in python is ment. As I understand there doesn't exist public / protected / private mechanism, but a '_' and '__' naming convention. As I figured out there is only public and private possible as speakin in "C++ manner". Are you all happy with it. What does "the zen of python" say to that design? (protected is useless?) class A: def __init__(self): self.__z = 1 self._z = 2 self.z = 3 def _getX(self): return "X" def __getY(self): return "Y" def doAnything(self): print self.__getY() class B(A): def __init__(self): A.__init__(self) print dir (self) >>> b = B() ['_A__getY', '_A__z', '__doc__', '__init__', '__module__', '_getX', '_z', 'doAnything', 'z'] I was a bit surprised about '_A__getY' and '_A__z'. What would you say to a C++ Programmer about class interfaces in big Python systems? What is the idea behind the _ and __ naming. Use or don't use '_' methods ? (As Designer of the software, as Programmer of the software) Regards Alexander -- http://mail.python.org/mailman/listinfo/python-list
Howto pass exceptions between threads
Hallo Alltogether, I've searched in this mailing list, but it seems to me that there is no general approach to pass exceptions from one thread to another. I think most application do a unique way of handling "unhandled exceptions", at least they (should) try to log them. The following discussion seems to me most valuable (Sorry for the long URL, I don't know a way of shorter) http://groups.google.de/group/comp.lang.python/browse_frm/thread/a2ebb2a2f611779b/4b820c20ff3fcea8?lnk=gst&q=%2Bexception+%2Bthread&rnum=6&hl=de#4b820c20ff3fcea8 http://groups.google.de/group/comp.lang.python/browse_frm/thread/2c61c06795f525f3/348a8d9e85883fe3?lnk=gst&q=pass+%2Bexception+%2Bthread&rnum=1&hl=de#348a8d9e85883fe3 I've the feeling that if you're using the python class threading.Thread you've a unique interface of handling it. (thread synchronizing + exception raising) But' when you've a C++ extension, that uses it's own thread implementation and your exceptions happens in python code (but from a thread that is controlled by your extension) you have another problem. Maybe I've overseen something in the python docu, so I ask for the solutions, concepts, hints ... you solved the problem. Regards Alexander -- http://mail.python.org/mailman/listinfo/python-list
Re: Howto pass exceptions between threads
John Nagle schrieb: > Alexander Eisenhuth wrote: >> Hallo Alltogether, >> >> I've searched in this mailing list, but it seems to me that there is >> no general approach to pass exceptions from one thread to another. > >Very few languages have that. > >Actually, it could be made to work for Python, but it would have to > be carefully designed. Something that raises an exception in another > thread the next time the thread blocks would have relatively sane > semantics. You couldn't raise an exception on a compute-bound thread, > only at block points (locks, I/O, long system calls.) > > John Nagle Yes you're right, it must be well designed with a clear responsibility delegation. I can imgagine the following points: - Thread termination with termination handler (for Thread instance) - Main Thread information / synchronisation - Default/Customized main thread exception handler -- http://mail.python.org/mailman/listinfo/python-list
Howto find dict members from a list of keys
Hello, what algo do you use, when you want to find the dict values from d, with members of l. Following example: >>> d = {1:2,2:3,3:4,4:5,5:6,6:7,7:8,8:9,9:10} >>> l = [7,8] >>> found_dic_members = >>> print found_dict_members [8,9] Thanks Alexander -- http://mail.python.org/mailman/listinfo/python-list
Re: Howto find dict members from a list of keys
Yes it was the silly on-liner ... it was a bit ago I used it last time ... thanks Gabriel Genellina schrieb: > En Thu, 08 Mar 2007 05:37:48 -0300, Steven D'Aprano > <[EMAIL PROTECTED]> escribió: > >> On Thu, 08 Mar 2007 05:26:22 -0300, Gabriel Genellina wrote: >> >>> found_dic_members = [d[key] for key in l] >> >> *self stares at the line of code* >> >> *self thinks about what he just posted* >> >> *self realises with acute embarrassment that he's jumped to conclusions >> and completely misunderstood the Original Poster's question* >> >> Oops! I'll just be slinking away now... > > LOL! :) > > (...now! But when I saw your previous post, I had to check whether it > was *me* who misunderstood the OP answering with a silly one-liner...) > > > --Gabriel Genellina > -- http://mail.python.org/mailman/listinfo/python-list
String formatting with fixed width
Hello alltogether, is it possible to format stings with fixed width of let's say 7 character. T need a floating point with 3 chars before dot, padded with ' ' and 3 chars after dot, padded with '0'. Followingh is my approach >>> f = 21.1 >>> s = "%.03f" % f >>> s '21.100' But there are missing ' '. How can I get that? (For bigger numbers than 999 they might be cut: 1021 -> 021) Alexander -- http://mail.python.org/mailman/listinfo/python-list
String formatting with fixed width
Hello alltogether, is it possible to format stings with fixed width of let's say 7 character. T need a floating point with 3 chars before dot, padded with ' ' and 3 chars after dot, padded with '0'. Followingh is my approach >>> f = 21.1 >>> s = "%.03f" % f >>> s '21.100' But there are missing ' '. How can I get that? (For bigger numbers than 999 they might be cut: 1021 -> 021) Thanks, Alexander -- http://mail.python.org/mailman/listinfo/python-list
Re: String formatting with fixed width
Thanks for your fast reply. I'm fine with your "%7.03f" solution. (negatives are not significant) Alexander Eisenhuth schrieb: > Hello alltogether, > > is it possible to format stings with fixed width of let's say 7 > character. T need a floating point with 3 chars before dot, padded with > ' ' and 3 chars after dot, padded with '0'. > > Followingh is my approach > >>> f = 21.1 > >>> s = "%.03f" % f > >>> s > '21.100' > > But there are missing ' '. How can I get that? (For bigger numbers than > 999 they might be cut: 1021 -> 021) > > Thanks, > Alexander -- http://mail.python.org/mailman/listinfo/python-list
PyQt disconnect signal / slot
Hello PyQt experts, do i have to disconnect all signal/slots, after the emitting object is deleted, or does it the QObject destructor? Thanks Alexander -- http://mail.python.org/mailman/listinfo/python-list
Re: PyQt disconnect signal / slot
Phil, thanks for that quick reply Phil Thompson schrieb: > On Tuesday 25 September 2007, Alexander Eisenhuth wrote: >> Hello PyQt experts, >> >> do i have to disconnect all signal/slots, after the emitting object is >> deleted, or does it the QObject destructor? > > It's done for you - same as Qt. > > Phil -- http://mail.python.org/mailman/listinfo/python-list
Heap problems in Mulithreaded Python extension
Hi, I'm near the ground and need help. I'm building a multithreaded extension with boost.python. python extension - import extension extension.init() ->PyEval_InitThreads(); setup 3 threads (pthreads) and do a lot of things, but no python api calls while true: time.sleep(0.1) PyGILState_STATE gGILState; gGILState = PyGILState_Ensure(); (...) // Do python API calls PyGILState_Release(gGILState); So my questions: - Is it enough to do the following in the extension, regardless wich thread it does ? PyGILState_STATE gGILState; gGILState = PyGILState_Ensure(); (...) // Do python API calls PyGILState_Release(gGILState); What happens is, that inside the extension (C++) from time to time _CrtIsValidHeapPointer(...) fails. Any comments/experience on "python and threaded extensions" is very welcome. Alexander -- http://mail.python.org/mailman/listinfo/python-list
Re: Heap problems in Mulithreaded Python extension
ok, once more my "scheme" python extension - import extension extension.init() ->PyEval_InitThreads(); setup 3 threads (pthreads) and do a lot of things, but no python api calls while true: time.sleep(0.1) PyGILState_STATE gGILState; gGILState = PyGILState_Ensure(); (...) // Do python API calls PyGILState_Release(gGILState); -- http://mail.python.org/mailman/listinfo/python-list
Build Python 2.5 wit VC6.0 ?
Hi everybody, does somebody have experience in building with VC6.0. On my first try there where missing C-Modules. Is that true. VC6.0 is not supported? Thanks a lot. Regards Alexander PC: What Python version supports VC6.0? -- http://mail.python.org/mailman/listinfo/python-list
What is bad with "Relative imports"
Hi, PyLint says that "Relative imports" ... are worth to be warned . And I ask myself why? - Example directory structure - Sound/ Top-level package __init__.py Initialize the sound package Utils/ Subpackage __init__.py iobuffer.py errors.py misc.py ... Formats/ Let's say in misc.py exist the class Player(). What could be bad to expose it in Utils.__init__() like: -- __init__.py - import misc # provoke PyLint warning Player = misc.Player ... with Sound.Utils.Player() ?? Thaks for your experience and comments Regards Alexander -- http://mail.python.org/mailman/listinfo/python-list
PyGILState_Ensure() produces a deadlock
Hello, In my mixed C++ / Python Application there are situations where a PyGILState_STATE gil_state = PyGILState_Ensure() produces a deadlock. The background is that a call fro python to cpp is directed to another subsystem that tries to access the GIL (through my C++ wrapper) from another thread. Does Pyhon API offer services to ship around that? Other hints? Thanks a lot -- http://mail.python.org/mailman/listinfo/python-list
boost.python Event object wrapped with bp::object()
Hello everybody, I Use a C++ thread that is called from the python sides to provoke some activities. The calls set some booleans in the thread object and return. To synchrThreadClassonize the execution in the thread, the idea of me is, to give a Python Event() object as bp::object to the C++ thread, that calls the python "set" attribute after the related activity has finished. Maybe this code is clearer: Python: thread = wrapper.ThreadClass() event = Event() thread.methode(event) event.wait() C++: ThreadClass::methode(bp::object event) { this->myEvent = event ... methodeCalled = true ... } ThreadClass::threadLoop() { ... if (methodeCalled) { ... this->myEvent.attr("set")(); } } The application crashes. If I comment out event.wait() it doesn't crash. Any suggestions or experiances? Thanks a lot Alexander -- http://mail.python.org/mailman/listinfo/python-list
(pywin related) pywintypes.com_error: -2147417846 "Application busy"
Hello list, I'm having a problem with a python COM Excel client that rarely gets the exception pywintypes.com_error with the error code -2147417846. (means Excel is busy) Here the python code of the exception handling: [...] try: # write a excel cell [...] except pywintypes.com_error, ex: if ex[0] == -2147417846: time.sleep(1.0) # retry write? [...] My first approach was to retry the writing to the excel cell. But that ends in a hanging Excel application (probably a deadlock). After a little research I found this post: http://social.msdn.microsoft.com/Forums/en-US/vsto/thread/70ef972b-51b6-4ece-a4af-d6b4e111eea5 "[...] If you don't register a MessageFilter yourself (by calling CoRegisterMessageFilter), you will get default behavior which will be to fail the call if it gets rejected. .Net converts the failure HRESULT to an exception. To deal with the possibility of the server being busy when you try to call, you need to implement IMessageFilter::RetryRejectedCall in your client code and also register the message filter. In most cases, you will just need to wait for a few seconds and then retry the call--generally that will be sufficient time to enable Word to finish whatever it is doing so it can handle your call. However, if the instance of Word that you are controlling could possibly visible, you might want to add additional logic to display the OLEUIBUSY dialog after some amount of time has passed to notify the user that you are waiting on Word to do something and give them the opportunity to help the process. For example, as Misha mentions, Word will reject all incoming calls if a modal dialog box is up. Therefore, in that situation, you would be blocked indefinitely until the dialog is dismissed. [...]" As this part of the COM API (IMessageFilter, CoRegisterMessageFilter) isn't included in pywin32 I don't see a possibility to do that, or? Did anybody else have to deal with that problem? Any hints are very welcome. Regards Alexander -- http://mail.python.org/mailman/listinfo/python-list
Re: (pywin related) pywintypes.com_error: -2147417846 "Application busy"
I don't think so, because it happens very rarely Michel Claveau - MVP schrieb: Hi! Your computer is too slow, for launch Excel. Configure the machine for more speed... @+ -- http://mail.python.org/mailman/listinfo/python-list
__slot__: what is it good for?
Hello out there, - what is the reason, that __slots__ are introduced in python? - I want to use slots to define a class where no attributes are added at runtime. Is that a good idea to use slots for that? Regards Alexander -- http://mail.python.org/mailman/listinfo/python-list
Howto write XML file with comments?
Hello, - I've to write a XML document including comments - the document should be formatted that it could be viewed with a text editor What is the fastest (time for realization) approach doing it in python 2.5? Any help or hints are very welcome Thanks Alexander -- http://mail.python.org/mailman/listinfo/python-list
Re: Howto write XML file with comments?
Stefan Behnel schrieb: Alexander Eisenhuth, 08.07.2010 11:08: - I've to write a XML document including comments "write" in the sense of typing in a text editor? Or constructing one programmatically in memory? Or ... ? write means write to a file And what kind of data from what kind of source do you want to put into the document? Data is present as tags and attributes All of that has an impact on the 'right' answer. - the document should be formatted that it could be viewed with a text editor What is the fastest (time for realization) approach doing it in python 2.5? If you mean to build an XML document programmatically, potentially using data that you get from somewhere, take a look at cElementTree. There's also a short recipe for pretty printing the tree before writing it out. Is the API of cElementTree different from ElementTree in the python standard library? Stefan -- http://mail.python.org/mailman/listinfo/python-list
Re: Howto write XML file with comments?
Sorry for my little riddle, but you solved it quite good with: - http://effbot.org/zone/element-lib.htm#prettyprint and comments are also in ElementTree (xml.etree.ElementTree.Comment) Thanks Stefan Behnel schrieb: Alexander Eisenhuth, 08.07.2010 12:07: Stefan Behnel schrieb: Alexander Eisenhuth, 08.07.2010 11:08: - I've to write a XML document including comments "write" in the sense of typing in a text editor? Or constructing one programmatically in memory? Or ... ? write means write to a file You seam to imply that it's obvious what you want to do. From the little information that you give us, it's not. And what kind of data from what kind of source do you want to put into the document? Data is present as tags and attributes Whatever that is supposed to mean in this context. All of that has an impact on the 'right' answer. ... and it still does. - the document should be formatted that it could be viewed with a text editor What is the fastest (time for realization) approach doing it in python 2.5? If you mean to build an XML document programmatically, potentially using data that you get from somewhere, take a look at cElementTree. There's also a short recipe for pretty printing the tree before writing it out. Is the API of cElementTree different from ElementTree in the python standard library? Same thing, different import. Note that both were updated in Py2.7, BTW. Stefan -- http://mail.python.org/mailman/listinfo/python-list
ValueError: invalid literal for float(): -1.#IND (pickle.py)
Hello together, python: 2.5.1 palttform: winXP I'm using pickle.dump and pickle.load with data that is created in a wrapped (boost.python) piece of C++ code. pickle.dump works fine. pickle.load creates the following exception: [...] data = pickle.load(input) File "C:\Python25\lib\pickle.py", line 1370, in load return Unpickler(file).load() File "C:\Python25\lib\pickle.py", line 858, in load dispatch[key](self) File "C:\Python25\lib\pickle.py", line 954, in load_float self.append(float(self.readline()[:-1])) ValueError: invalid literal for float(): -1.#IND - I'm not sure what -1.#IND means. Can somebody assist? - As pickle write the data I'm a bit confused, that is can't be unpickled it. Is that a bug or a feature? BTW: I'm tied to version 2.5 of python Thank and regards Alexander -- http://mail.python.org/mailman/listinfo/python-list
Re: ValueError: invalid literal for float(): -1.#IND (pickle.py)
Mark Dickinson schrieb: BTW: I'm tied to version 2.5 of python Have you tried using pickle protocol 1 or 2, instead of pickle protocol 0? That may well solve your problem. (Those protocols write out the binary form of a float directly, instead of reading and writing a string representation.) Thanks a lot, it looks like it solves the problem using another version of the protocol Regards -- http://mail.python.org/mailman/listinfo/python-list