From itcecsa at gmail.com Mon Dec 3 07:38:31 2007 From: itcecsa at gmail.com (Guofu Chen) Date: Mon, 3 Dec 2007 01:38:31 -0500 Subject: [capi-sig] Can you tell me how to launch Matlab and run M-files from Python? Message-ID: Hi, I am now implementing a small Python project, what I am going to do is to lunch Matlab and run some M-files, and get some output from Matlab command prompt. This project will be used on both Windows 32 and Linux. I have no idea how to open Matlab from Python! Do I have to make Matlab C/C++ source codes to be Python modules so that they can be called by Python? Any suggestions would be appreciated! From manohar.gujja at gmail.com Mon Dec 3 07:51:03 2007 From: manohar.gujja at gmail.com (Vijay Manohar) Date: Mon, 3 Dec 2007 12:21:03 +0530 Subject: [capi-sig] How to do C api testing with python Message-ID: <5c5affda0712022251l77367200m99036b48792ed8a7@mail.gmail.com> Hi All, I have been working with python for a month, I have really loved using python for testing different tools and basically in automating the GUI related to windows, and also on web. Now I have a huge task to test in front of me, we are developing an API, and I feel like I have to test the API so that I have to make sure that how well it works in a given typical failure conditions. Can anyone suggest me how to do API testing of C using python. I have searched out in google and only found a link which creates a wrapper around the api and uses. But I would like to test the API in a pythonic way. Any help is really appreciated. with regards, Manohar Gujja From mal at egenix.com Mon Dec 3 10:48:54 2007 From: mal at egenix.com (M.-A. Lemburg) Date: Mon, 03 Dec 2007 10:48:54 +0100 Subject: [capi-sig] How to do C api testing with python In-Reply-To: <5c5affda0712022251l77367200m99036b48792ed8a7@mail.gmail.com> References: <5c5affda0712022251l77367200m99036b48792ed8a7@mail.gmail.com> Message-ID: <4753D106.2090606@egenix.com> On 2007-12-03 07:51, Vijay Manohar wrote: > Hi All, > > I have been working with python for a month, I have really loved using > python for testing different tools and basically in automating the GUI > related to windows, and also on web. > Now I have a huge task to test in front of me, we are developing an API, and > I feel like I have to test the API so that I have to make sure that how well > it works in a given typical failure conditions. > Can anyone suggest me how to do API testing of C using python. > > I have searched out in google and only found a link which creates a wrapper > around the api and uses. > > But I would like to test the API in a pythonic way. > > Any help is really appreciated. You could use an extension module for this, much like Python itself does with _testcapimodule.c. Alternatively, you might want to look at the ctypes module. However, I'd only recommend that if you already have a good feeling that most of the C API you're testing does work, since ctypes indirects the testing. -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Source (#1, Dec 03 2007) >>> Python/Zope Consulting and Support ... http://www.egenix.com/ >>> mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ :::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,MacOSX for free ! :::: eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48 D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg Registered at Amtsgericht Duesseldorf: HRB 46611 From cyril.bazin at info.unicaen.fr Mon Dec 3 10:07:12 2007 From: cyril.bazin at info.unicaen.fr (Cyril Bazin) Date: Mon, 3 Dec 2007 10:07:12 +0100 Subject: [capi-sig] [C++-sig] Can you tell me how to launch Matlab and run M-files from Python? In-Reply-To: References: Message-ID: If you want to matlab in python like if it was runned from the command line, use the python module "subprocess". This module requieres at least the version 2.4 of python. http://docs.python.org/lib/module-subprocess.html Cyril On Dec 3, 2007 7:38 AM, Guofu Chen wrote: > Hi, > > I am now implementing a small Python project, what I am going to do is to > lunch Matlab and run some M-files, and get some output from Matlab command > prompt. This project will be used on both Windows 32 and Linux. > > I have no idea how to open Matlab from Python! Do I have to make Matlab > C/C++ source codes to be Python modules so that they can be called by > Python? > > Any suggestions would be appreciated! > _______________________________________________ > C++-sig mailing list > C++-sig at python.org > http://mail.python.org/mailman/listinfo/c++-sig > > From gjcarneiro at gmail.com Tue Dec 4 19:05:10 2007 From: gjcarneiro at gmail.com (Gustavo Carneiro) Date: Tue, 4 Dec 2007 18:05:10 +0000 Subject: [capi-sig] ANNOUNCE: PyBindGen 0.8 Message-ID: The other day I released PyBindGen 0.8. Main news is that it features a new experimental header file scanner based on pygccxml (i.e., it's similar to py++ in scope, if not in maturity, but does not use boost.pythonunderneath). == What == PyBindGen is a Python module that is geared to generating C/C++ code that binds a C/C++ library for Python. It does so without extensive use of either C++ templates or C pre-processor macros. It has modular handling of C/C++ types, and can be easily extended with Python plugins. The generated code is almost as clean as what a human programmer would write, and does not depend on any library or header files besides Python itself. == Where == https://launchpad.net/pybindgen/ == NEWS == - Support C++ instance attributes through getter/setter methods - Support functions as methods of C++ classes - Support the PyObject* type - Support unsigned int, C strings (char*) (from Mark Lee) - Add basic support for enum types - New experimental automatic module generator based on C/C++ header file scanner and annotations in comments, using pygccxml - Some bug fixes -- Gustavo J. A. M. Carneiro INESC Porto, Telecommunications and Multimedia Unit "The universe is always one step beyond logic." -- Frank Herbert From sndive at gmail.com Thu Dec 6 00:56:04 2007 From: sndive at gmail.com (Anton Tropashko) Date: Wed, 5 Dec 2007 17:56:04 -0600 Subject: [capi-sig] is there a tp_getattr equivalent for module? Message-ID: <2822e000712051556g15bcaa9bt8568baf35ecd3c12@mail.gmail.com> is there a tp_getattr equivalent for module? i want to dynamically check if an object exists in a module space dynamically and return it if it does. currently i have mymodule.getattr("foo") where getattr is my lookup function plugged thru PyMethodDef/Py_ModuleInit i want to be able to access foo directly, like so: mymodule.foo From cbarton at metavr.com Fri Dec 7 13:35:09 2007 From: cbarton at metavr.com (Campbell Barton) Date: Fri, 07 Dec 2007 13:35:09 +0100 Subject: [capi-sig] is there a tp_getattr equivalent for module? In-Reply-To: <2822e000712051556g15bcaa9bt8568baf35ecd3c12@mail.gmail.com> References: <2822e000712051556g15bcaa9bt8568baf35ecd3c12@mail.gmail.com> Message-ID: <1197030909.16847.5.camel@quiet-cow.lan> would this work? PyObject *mod_sys; mod_sys = PyImport_ImportModule( "sys" ); /* new ref */ dict = PyModule_GetDict( mod_sys ); /* borrowed ref */ PyObject *key, *value; int pos = 0; if (dict) { while (PyDict_Next(dict, &pos, &key, &value)) { /* do stuff here */ } } On Wed, 2007-12-05 at 17:56 -0600, Anton Tropashko wrote: > is there a tp_getattr equivalent for module? > i want to dynamically check if an object exists in a module space > dynamically > and return it if it does. > > currently i have > mymodule.getattr("foo") > where getattr is my lookup function plugged thru PyMethodDef/Py_ModuleInit > > i want to be able to access foo directly, like so: > mymodule.foo > _______________________________________________ > capi-sig mailing list > capi-sig at python.org > http://mail.python.org/mailman/listinfo/capi-sig From gjcarneiro at gmail.com Fri Dec 7 15:00:17 2007 From: gjcarneiro at gmail.com (Gustavo Carneiro) Date: Fri, 7 Dec 2007 14:00:17 +0000 Subject: [capi-sig] is there a tp_getattr equivalent for module? In-Reply-To: <1197030909.16847.5.camel@quiet-cow.lan> References: <2822e000712051556g15bcaa9bt8568baf35ecd3c12@mail.gmail.com> <1197030909.16847.5.camel@quiet-cow.lan> Message-ID: On 07/12/2007, Campbell Barton wrote: > > would this work? > > PyObject *mod_sys; > > mod_sys = PyImport_ImportModule( "sys" ); /* new ref */ > dict = PyModule_GetDict( mod_sys ); /* borrowed ref */ Don't do this, it breaks the module as object transparency. In some solutions, python modules can be replaced by proxy objects that deman load the real object, and they hook into getattr, so this solution won't work for them. Modules are normal python objects. You can use PyObject_GetAttrString as usual... PyObject *key, *value; > int pos = 0; > > if (dict) { > while (PyDict_Next(dict, &pos, &key, &value)) { > /* do stuff here */ > } > } > > > > > On Wed, 2007-12-05 at 17:56 -0600, Anton Tropashko wrote: > > is there a tp_getattr equivalent for module? > > i want to dynamically check if an object exists in a module space > > dynamically > > and return it if it does. > > > > currently i have > > mymodule.getattr("foo") > > where getattr is my lookup function plugged > thru PyMethodDef/Py_ModuleInit > > > > i want to be able to access foo directly, like so: > > mymodule.foo > > _______________________________________________ > > capi-sig mailing list > > capi-sig at python.org > > http://mail.python.org/mailman/listinfo/capi-sig > > _______________________________________________ > capi-sig mailing list > capi-sig at python.org > http://mail.python.org/mailman/listinfo/capi-sig > -- Gustavo J. A. M. Carneiro INESC Porto, Telecommunications and Multimedia Unit "The universe is always one step beyond logic." -- Frank Herbert From hniksic at xemacs.org Fri Dec 7 15:33:16 2007 From: hniksic at xemacs.org (Hrvoje Niksic) Date: Fri, 07 Dec 2007 15:33:16 +0100 Subject: [capi-sig] is there a tp_getattr equivalent for module? In-Reply-To: <2822e000712051556g15bcaa9bt8568baf35ecd3c12@mail.gmail.com> (Anton Tropashko's message of "Wed\, 5 Dec 2007 17\:56\:04 -0600") References: <2822e000712051556g15bcaa9bt8568baf35ecd3c12@mail.gmail.com> Message-ID: <87k5nq4lsj.fsf@mulj.homelinux.net> "Anton Tropashko" writes: > is there a tp_getattr equivalent for module? i want to dynamically > check if an object exists in a module space dynamically and return > it if it does. You don't need to call tp_getattr yourself, PyObject_GetAttr will do it for you. If you need to check whether an object exists in a module without accessing it using mymodule.name, simply use getattr on the module object like you'd do with any other object. For example: import mymodule name = 'foo' if hasattr(mymodule, name): print 'mymodule has', name, 'and its value is', getattr(mymodule, name) else: print 'no', name, 'in mymodule' Equivalent C code would use PyObject_HasAttr/PyObject_GetAttr or its *String variants. From gjcarneiro at gmail.com Sat Dec 8 13:19:10 2007 From: gjcarneiro at gmail.com (Gustavo Carneiro) Date: Sat, 8 Dec 2007 12:19:10 +0000 Subject: [capi-sig] [C++-sig] ANNOUNCE: PyBindGen 0.8 In-Reply-To: References: Message-ID: On 08/12/2007, Joseph Lisee wrote: > > That is very cool to here I have one concern and a few comments. I am not > sure > what to think of the annotations in the comments. It feel at same time > both a > hack because it replaces a API around your generator It does not really replace the API. Think of PyBindGen as two separate layers: 1. an low level API layer, and 2. header file scanning and annotations, which are built on top of that layer. The first layer would be needed anyway, for code modularity and readability. And the first layer can be used directly; I don't see any problem with that. and elegant because you > don't have to maintain a separate set of files to represent the > wrapping. The > downside of this is that you would have to modify the source of any code > you > would wish to wrap, and that will get quite cumbersome. It is very true. Sometimes you cannot modify the header files you're trying to wrap. On the other hand, experience tells me you can't fully automate wrapping C/C++ code without either 1) strict displine in the C/C++ code, to use certain memory management conventions (e.g. "callee should never take ownership of the objects in parameters"). or 2) the python bindings have extra information not explicit in the C language. Bottom line is, in the real world you cannot fully automate bindings; you need to give the bindings generator extra information besides the header files. Annotations is IMHO a nice way to give that extra information, when you can. Not only it's easier to follow the annotations since they're right next to the API declarations, but it gives information that even C/C++ coders will find useful. How to enter annotations when you can't modify the header files is, however, an open question. I don't have a clear answer yet, and suggestions are welcome. I am also wondering if you have decent support for standard containers? > Something like Boost.Python indexing suite version 2. Right again. PyBindGen does not have that as of yet. I would like to implement it some day. But I don't think it's as hard as it sounds, so don't lose hope just yet :) One question, though, if someone can answer. How does BP indexing suite map e.g. sequence containers? Just convert all elements to a python list? Or does it implement an object that supports iteration and sequence special methods? BTW, there are more limitations in PyBindGen that people should be aware of, such as: - Does not support multiple inheritance (I don't like MI and have no plans to implement it any time soon, unless a patch is brought to me); - Generates a single potentially big C/C++ file, no splitting done as of yet; - No support yet for one module importing definitions from another module; - Definitions nested inside class namespaces not supported (though should not be hard to implement); Thanks for the comments, -- Gustavo J. A. M. Carneiro INESC Porto, Telecommunications and Multimedia Unit "The universe is always one step beyond logic." -- Frank Herbert From integrates at rivercafe.co.uk Thu Dec 13 21:34:39 2007 From: integrates at rivercafe.co.uk (Lajoie Gouker) Date: Thu, 13 Dec 2007 20:34:39 +0000 Subject: [capi-sig] baptizables Message-ID: <8827743038.20071213202955@rivercafe.co.uk> Guten Tag, Virus found in this message, please delete it without futher reading He nodded. Keep quite quiet, though, and don't to expand into that territory to the north and here?' 'no murder ever took place here,' said. From supplicant at ladypeddler.net Fri Dec 14 08:18:45 2007 From: supplicant at ladypeddler.net (Cowing Maslonka) Date: Fri, 14 Dec 2007 07:18:45 +0000 Subject: [capi-sig] lamebrain Message-ID: <7063343587.20071214070854@ladypeddler.net> Hola, Virus found in this message, please delete it without futher reading A cheque and a signed photograph arrived on the anything for us. You see i've brought prog enough such circumstancesyelled at the top of their voices,. From andreas.raab at gmx.de Tue Dec 18 01:07:48 2007 From: andreas.raab at gmx.de (Andreas Raab) Date: Mon, 17 Dec 2007 16:07:48 -0800 Subject: [capi-sig] Deploying embedded Python Message-ID: <47670F54.20104@gmx.de> Hi - I'm currently looking into a few deployment issues with our embedded Python interpreter and I'm looking for any information about deploying embedded Python that people may have. Specifically, I'm looking for the following information: 1) How to define a useful subset of the stdlib that can serve as an initial basis for the installation but later allows upgrade to the "full" library if desirable. In other words, I'd like to deploy a small subset of the stdlib to begin with (simply because of size constraints) which may later be extended to a full stdlib if this is desirable. Has someone done this before? I'd love to have a small "Python.zip" cross-platform stdlib surrogate that just gets shipped with the product. If not, what is the right starting point for analyzing the dependencies inside the stdlib? 2) How to isolate the embedded interpreter from environmental effects. I have found that on occasion, the interpreter would pick up "stray" installations which can cause weird problems. Which environmental settings affect the startup of an embedded Python interpreter? How does one work around/remove those dependencies? Is there any information available about how exactly the startup works? What is being read/loaded in which order etc? 3) General advice about deploying embedded Python. Pointers to web sites, general experience (good or bad) etc. are all very welcome. Thanks, - Andreas From theeth at yahoo.com Thu Dec 20 17:24:48 2007 From: theeth at yahoo.com (Martin Poirier) Date: Thu, 20 Dec 2007 08:24:48 -0800 (PST) Subject: [capi-sig] Deploying embedded Python In-Reply-To: <47670F54.20104@gmx.de> Message-ID: <107834.39023.qm@web51301.mail.re2.yahoo.com> Hi, --- Andreas Raab wrote: > 1) How to define a useful subset of the stdlib that > can serve as an > initial basis for the installation but later allows > upgrade to the > "full" library if desirable. In other words, I'd > like to deploy a small > subset of the stdlib to begin with (simply because > of size constraints) > which may later be extended to a full stdlib if this > is desirable. Has > someone done this before? I'd love to have a small > "Python.zip" > cross-platform stdlib surrogate that just gets > shipped with the product. > If not, what is the right starting point for > analyzing the dependencies > inside the stdlib? We do that for windows version of Blender ( http://www.blender.org/ ) (other OSes are assumed to have a full python distro already). What we did to select the different modules included was very arbitrary. We picked the minimal set of modules that was required by scripts we wanted to ship with Blender at this point. With passing releases, we added some more, trying to keep size low (one of the reasons we don't include the xml parsing modules, IIRC). Currently, this includes os (and its dependencies), random, webbrowser, threading, struct, tokenize, ... I really wouldn't recommend the method we used to get dependency, which was (if memory serves right) a mix of looking at the sources and trial/error on a test machine, adding missing dependencies until it worked. > 2) How to isolate the embedded interpreter from > environmental effects. I > have found that on occasion, the interpreter would > pick up "stray" > installations which can cause weird problems. Which > environmental > settings affect the startup of an embedded Python > interpreter? How does > one work around/remove those dependencies? Is there > any information > available about how exactly the startup works? What > is being read/loaded > in which order etc? That's an excellent question. I'm not sure if we came up with a viable solution for that problem either, so if anybody else would like to pitch in an answer, we'd appreciate too. This particular problem causes much pain when people have binary modules from older versions of Python in their import paths. > 3) General advice about deploying embedded Python. > Pointers to web > sites, general experience (good or bad) etc. are all > very welcome. >From experience, unless you want to limit python input to things included with the distribution of your software, I'd say limit the included modules to the bare minimum, otherwise it's easy to get to a point where you're pretty much including the whole Python distro anyway, so might as well ask your users to install that directly. I hope that was a bit helpful. Martin PS: Apologies to Andreas for the double post, I sent my original email to you directly instead of the list, as I intended. ____________________________________________________________________________________ Be a better friend, newshound, and know-it-all with Yahoo! Mobile. Try it now. http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ From andreas.raab at gmx.de Thu Dec 20 22:16:56 2007 From: andreas.raab at gmx.de (Andreas Raab) Date: Thu, 20 Dec 2007 13:16:56 -0800 Subject: [capi-sig] Deploying embedded Python In-Reply-To: <485388.43955.qm@web51303.mail.re2.yahoo.com> References: <485388.43955.qm@web51303.mail.re2.yahoo.com> Message-ID: <476ADBC8.8020100@gmx.de> Martin Poirier wrote: > We do that for windows version of Blender ( > http://www.blender.org/ ) (other OSes are assumed to > have a full python distro already). > > What we did to select the different modules included > was very arbitrary. We picked the minimal set of > modules that was required by scripts we wanted to ship > with Blender at this point. With passing releases, we > added some more, trying to keep size low (one of the > reasons we don't include the xml parsing modules, > IIRC). > > Currently, this includes os (and its dependencies), > random, webbrowser, threading, struct, tokenize, ... That sounds quite like the approach we'll be taking ;-) I'll check Blender to see how your subset compares to what I have right now. > I really wouldn't recommend the method we used to get > dependency, which was (if memory serves right) a mix > of looking at the sources and trial/error on a test > machine, adding missing dependencies until it worked. Yes, this is one of the reasons why I'm asking. Despite the (rather nice) Python module system there doesn't seem to be much integrity checking for modules, i.e., whether the set of modules you have is logically consistent (if there is, please let me know). I think the only way to test this is to run a test suite and see if it works or not. >> 2) How to isolate the embedded interpreter from >> environmental effects. > > That's an excellent question. I'm not sure if we came > up with a viable solution for that problem either, so > if anybody else would like to pitch in an answer, we'd > appreciate too. I think Anthony's message addresses this problem quite well. >> 3) General advice about deploying embedded Python. >> Pointers to web >> sites, general experience (good or bad) etc. are all >> very welcome. > > From experience, unless you want to limit python input > to things included with the distribution of your > software, I'd say limit the included modules to the > bare minimum, otherwise it's easy to get to a point > where you're pretty much including the whole Python > distro anyway, so might as well ask your users to > install that directly. > > I hope that was a bit helpful. Indeed you were. Thanks a bunch! Cheers, - Andreas From jeff at taupro.com Fri Dec 21 08:30:35 2007 From: jeff at taupro.com (Jeff Rush) Date: Fri, 21 Dec 2007 01:30:35 -0600 Subject: [capi-sig] Deploying embedded Python In-Reply-To: <47670F54.20104@gmx.de> References: <47670F54.20104@gmx.de> Message-ID: <476B6B9B.9090907@taupro.com> Andreas Raab wrote: > > 1) How to define a useful subset of the stdlib that can serve as an > initial basis for the installation but later allows upgrade to the > "full" library if desirable. There is no formal way of doing this, although you could at least start with the full library and remove the really exotic stuff, like that for other platforms and audio/video/crypto packages. One man's worthless package is another's absolute requirement though. > 2) How to isolate the embedded interpreter from environmental effects. I > have found that on occasion, the interpreter would pick up "stray" > installations which can cause weird problems. Which environmental > settings affect the startup of an embedded Python interpreter? How does > one work around/remove those dependencies? Is there any information > available about how exactly the startup works? What is being read/loaded > in which order etc? If you are picking up stray installations it is probably through the PYTHONPATH environment variable. For a brief understanding of these, run the command "python --help". For your embedded world, you ought to change your distributed code to use a different environment variable, maybe a prefix or suffix. A useful tool in understanding the startup sequence of Python is the "-v" option, which will display the various imports that occur. It stays in effect, so it is also useful to watch the secondary imports that occur as your program executes. There have been several efforts in the Python community to isolate specific interpreter instances from each other, although not in the sense of embedded work. Two different approaches have been taken, that of SetupTools (the base of Python Eggs) and that of zc.buildout which is a way of bringing together specific versions of packages into a runtime environment. The VirtualEnv program for Python is also good for ideas on how to do this, and is really cool too. The SetupTools approach is to sprinkle .pth files in the lib/python/site-packages/ directory, thereby enabling specific packages globally across an installation. The zc.buildout approach is less global but gives more rigorous control, by letting individual scripts insert specific package references during startup. So you end up with startup scripts like: import sys sys.path[0:0] = [ '/home/jeff/Clients/Johns/buildout/parts/zope2/lib/python', '/home/jeff/Clients/Johns/buildout/parts/thirdparty-checkouts', ] _interactive = True if len(sys.argv) > 1: import getopt _options, _args = getopt.getopt(sys.argv[1:], 'ic:') _interactive = False for (_opt, _val) in _options: if _opt == '-i': _interactive = True elif _opt == '-c': exec _val if _args: sys.argv[:] = _args execfile(sys.argv[0]) if _interactive: import code code.interact(banner="", local=globals()) that customize the environment and then run the interpreter on your choice of Python programs. Note that zc.buildout leaves the existing search path intact, so that you still have the problem of things leaking in from PYTHONPATH though. Hope this gives you some ideas, -Jeff From remi.k2620 at gmail.com Thu Dec 27 12:12:58 2007 From: remi.k2620 at gmail.com (Remi K.) Date: Thu, 27 Dec 2007 12:12:58 +0100 Subject: [capi-sig] Constants in classes? Message-ID: Hello, I am currently writing a python wrapper for the C++ SFML library ( http://sfml.sourceforge.net). I know there is PyModule_AddIntConstant for adding constants to a module, but how can I add a constant to one of my module's classes? Is there an easy way to wrap enumerations? Any help is appreciated :) From remi.k2620 at gmail.com Thu Dec 27 14:01:17 2007 From: remi.k2620 at gmail.com (Remi K.) Date: Thu, 27 Dec 2007 14:01:17 +0100 Subject: [capi-sig] Constants in classes? In-Reply-To: References: Message-ID: Thanks for the answer. I did what you told me after the module's initialisation, it compiles well, however when I try to load my module with python it throws the error: TypeError: can't set attributes of built-in/extension type 'sfColor' Any idea? On Dec 27, 2007 12:53 PM, Gustavo Carneiro wrote: > On 27/12/2007, Remi K. wrote: > > > Hello, > > I am currently writing a python wrapper for the C++ SFML library ( > > http://sfml.sourceforge.net). > > I know there is PyModule_AddIntConstant for adding constants to a > > module, > > but how can I add a constant to one of my module's classes? Is there an > > easy > > way to wrap enumerations? > > Any help is appreciated :) > > > Any type is an object: > > PyObject *enum_value = PyInt_FromLong(123); > PyObject_SetAttrString((PyObject *) &FooBar_Type, enum_value); > Py_DECREF(enum_value); > > -- > Gustavo J. A. M. Carneiro > INESC Porto, Telecommunications and Multimedia Unit > "The universe is always one step beyond logic." -- Frank Herbert From gjcarneiro at gmail.com Thu Dec 27 15:02:34 2007 From: gjcarneiro at gmail.com (Gustavo Carneiro) Date: Thu, 27 Dec 2007 14:02:34 +0000 Subject: [capi-sig] Constants in classes? In-Reply-To: References: Message-ID: On 27/12/2007, Remi K. wrote: > > Thanks for the answer. I did what you told me after the module's > initialisation, it compiles well, however when I try to load my module > with > python it throws the error: > TypeError: can't set attributes of built-in/extension type 'sfColor' > Any idea? OK, maybe that only works for types that can be subclassed. Alternatively: PyObject *enum_value = PyInt_FromLong(123); PyDict_SetItemString(FooBar_Type.tp_dict, "name", enum_value) Py_DECREF(enum_value); On Dec 27, 2007 12:53 PM, Gustavo Carneiro wrote: > > > On 27/12/2007, Remi K. wrote: > > > > > Hello, > > > I am currently writing a python wrapper for the C++ SFML library ( > > > http://sfml.sourceforge.net). > > > I know there is PyModule_AddIntConstant for adding constants to a > > > module, > > > but how can I add a constant to one of my module's classes? Is there > an > > > easy > > > way to wrap enumerations? > > > Any help is appreciated :) > > > > > > Any type is an object: > > > > PyObject *enum_value = PyInt_FromLong(123); > > PyObject_SetAttrString((PyObject *) &FooBar_Type, enum_value); > > Py_DECREF(enum_value); > > > > -- > > Gustavo J. A. M. Carneiro > > INESC Porto, Telecommunications and Multimedia Unit > > "The universe is always one step beyond logic." -- Frank Herbert > _______________________________________________ > capi-sig mailing list > capi-sig at python.org > http://mail.python.org/mailman/listinfo/capi-sig > -- Gustavo J. A. M. Carneiro INESC Porto, Telecommunications and Multimedia Unit "The universe is always one step beyond logic." -- Frank Herbert From remi.k2620 at gmail.com Thu Dec 27 15:53:37 2007 From: remi.k2620 at gmail.com (Remi K.) Date: Thu, 27 Dec 2007 15:53:37 +0100 Subject: [capi-sig] Constants in classes? In-Reply-To: References: Message-ID: It worked, thank you very much :) On Dec 27, 2007 3:02 PM, Gustavo Carneiro wrote: > On 27/12/2007, Remi K. wrote: > > > Thanks for the answer. I did what you told me after the module's > > initialisation, it compiles well, however when I try to load my module > > with > > python it throws the error: > > TypeError: can't set attributes of built-in/extension type 'sfColor' > > Any idea? > > > OK, maybe that only works for types that can be subclassed. > > Alternatively: > > PyObject *enum_value = PyInt_FromLong(123); > PyDict_SetItemString(FooBar_Type.tp_dict, "name", enum_value) > Py_DECREF(enum_value); > > On Dec 27, 2007 12:53 PM, Gustavo Carneiro < gjcarneiro at gmail.com> wrote: > > > > > On 27/12/2007, Remi K. wrote: > > > > > > > Hello, > > > > I am currently writing a python wrapper for the C++ SFML library ( > > > > http://sfml.sourceforge.net). > > > > I know there is PyModule_AddIntConstant for adding constants to a > > > > module, > > > > but how can I add a constant to one of my module's classes? Is there > > an > > > > easy > > > > way to wrap enumerations? > > > > Any help is appreciated :) > > > > > > > > > Any type is an object: > > > > > > PyObject *enum_value = PyInt_FromLong(123); > > > PyObject_SetAttrString((PyObject *) &FooBar_Type, enum_value); > > > Py_DECREF(enum_value); > > > > > > -- > > > Gustavo J. A. M. Carneiro > > > INESC Porto, Telecommunications and Multimedia Unit > > > "The universe is always one step beyond logic." -- Frank Herbert > > _______________________________________________ > > capi-sig mailing list > > capi-sig at python.org > > http://mail.python.org/mailman/listinfo/capi-sig > > > > > > -- > Gustavo J. A. M. Carneiro > INESC Porto, Telecommunications and Multimedia Unit > "The universe is always one step beyond logic." -- Frank Herbert > From remi.k2620 at gmail.com Sat Dec 29 17:56:06 2007 From: remi.k2620 at gmail.com (Remi K.) Date: Sat, 29 Dec 2007 17:56:06 +0100 Subject: [capi-sig] Problem with a sub-module Message-ID: Hi everybody, I have two modules: m1 = Py_InitModule3("PySFML", NULL, "Python binding for sfml (Simple Fast Media Library)"); m2 = Py_InitModule("sf", module_methods); Then I add a few classes, like Color, to m2. Then I make the first module contain the second one: PyModule_AddObject(m1, "sf", m2); This way I can do: from PySFML import * MyColor = sf.Color(0,0,0,255) I would like to be able to do this: from PySFML.sf import * MyColor = Color(0,0,0,255) However, it does not work: "ImportError: No module named sf" First, is what i want to do "correct"? I mean, is it non-standard? And if it is correct, how can I do it? Thanks in advance. From gjcarneiro at gmail.com Sat Dec 29 18:59:45 2007 From: gjcarneiro at gmail.com (Gustavo Carneiro) Date: Sat, 29 Dec 2007 17:59:45 +0000 Subject: [capi-sig] Problem with a sub-module In-Reply-To: References: Message-ID: On 29/12/2007, Remi K. wrote: > > Hi everybody, > I have two modules: > m1 = Py_InitModule3("PySFML", NULL, "Python binding for sfml (Simple > Fast Media Library)"); > > m2 = Py_InitModule("sf", module_methods); Try this: m2 = Py_InitModule("PySFML.sf", module_methods); Then I add a few classes, like Color, to m2. > Then I make the first module contain the second one: PyModule_AddObject(m1, "sf", m2); That is not needed. -- Gustavo J. A. M. Carneiro INESC Porto, Telecommunications and Multimedia Unit "The universe is always one step beyond logic." -- Frank Herbert From remi.k2620 at gmail.com Sat Dec 29 19:45:51 2007 From: remi.k2620 at gmail.com (Remi K.) Date: Sat, 29 Dec 2007 19:45:51 +0100 Subject: [capi-sig] Problem with a sub-module In-Reply-To: References: Message-ID: I have the error: "SystemError: dynamic module not initialized properly" I guess this is due to the fact that the initialized module's name is not the same as the init function. I tried this: m2 = Py_InitModule("sf", module_methods); I renamed the init function initsf. Then in setup.py, I replaced ext_modules=[ Extension('PySFML', \ by ext_modules=[ Extension('PySFML.sf', \ It created the library as sf.so, under the PySFML directory. Then I created a directory called PySFML, created an __init__.py file in it, in which I put: from sf import * I added in setup.py: package_dir = {'PySFML':'PySFML'}, packages=['PySFML'], so he copied __init__.py in the same directory as sf.so. Now it works like I wanted it to work. This is currently the only working solution I found. On Dec 29, 2007 6:59 PM, Gustavo Carneiro wrote: > On 29/12/2007, Remi K. wrote: > > > Hi everybody, > > I have two modules: > > m1 = Py_InitModule3("PySFML", NULL, "Python binding for sfml (Simple > > Fast Media Library)"); > > > > m2 = Py_InitModule("sf", module_methods); > > > Try this: > > m2 = Py_InitModule("PySFML.sf", module_methods); > > > Then I add a few classes, like Color, to m2. > > Then I make the first module contain the second one: > > PyModule_AddObject(m1, "sf", m2); > > > That is not needed. > > -- > Gustavo J. A. M. Carneiro > INESC Porto, Telecommunications and Multimedia Unit > "The universe is always one step beyond logic." -- Frank Herbert