473,804 Members | 4,269 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Extend Python

Hi All I have a problem with extentions of Python.

Background:
I'm workin within a large industrial control system and I have created
a Port for VxWorks. In the system we have different permissions
depending on which state the controller is in. To perform some actions
in some states may even injure or kill people. Therefor we need
"intelligen t" wrappers between Python and C-code.

My Question:
Swig offers some great features but is to basic for us. Is there
another program that creates more readble code that can be easily
edited? How much work is it to write our own wrappers?

//T

Sep 1 '05 #1
7 1657
PyQT is using SIP to wrap Qt : looks nice and works great for PyQt
which is a quite big wrapping. Never had the occation to use it myself
however, except for this.

Sep 1 '05 #2
What is Qt?

I have looked at PyQT and I can´t use it. I haven't tried it but the
PyQT license makes the program useless. :(

Any other suggestions?

Sep 1 '05 #3
SIP is not a commercial product and is released on a different license
than PyQt.
From the SIP docs

(http://www.river-bank.demon.co.uk/do...f.html#license)
1.1 License
SIP is licensed under the same terms as Python itself. SIP places no
restrictions on the license you may apply to the bindings you create.

On a side note.. there will be a GPL edition of PyQt sometime in the
future.
http://www.riverbankcomputing.co.uk/pyqt/roadmap.php

Sep 1 '05 #4
Try looking at ctypes -
http://starship.python.net/crew/theller/ctypes/

On 1 Sep 2005 05:12:21 -0700, To**********@gm ail.com wrote:
Hi All I have a problem with extentions of Python.

Background:
I'm workin within a large industrial control system and I have created
a Port for VxWorks. In the system we have different permissions
depending on which state the controller is in. To perform some actions
in some states may even injure or kill people. Therefor we need
"intelligent " wrappers between Python and C-code.

My Question:
Swig offers some great features but is to basic for us. Is there
another program that creates more readble code that can be easily
edited? How much work is it to write our own wrappers?

//T


Sep 1 '05 #5
> My Question:
Swig offers some great features but is to basic for us. Is there
another program that creates more readble code that can be easily
edited? How much work is it to write our own wrappers?


Not too much, and practicaly not at all if you want to wrap procedures
(not objects or types):
- marshaslling an argument list from Python to C and from C to Python
takes exactly 1 line of code,
- handling errors takes 2 lines of code (unless you want to do
something fancy with them; I mean just catching an exception and
getting the error message).
- entry in the PyMethodDef is one simple line
Bottomline: you need 5 additional lines of C code per procedure to
make it usable from Python.
Unless you have hundreds of procedures, there is no point in using
special tools to do that. Especially if you need full control over the
results.

regards,
Filip Dreger
--
Akademia Linuksa - http://www.akademia.linuksa.pl
Sep 1 '05 #6
On Thu, 1 Sep 2005 19:09:55 +0200, Filip Dreger <fd*****@amiga. pl> wrote:
My Question:
Swig offers some great features but is to basic for us. Is there
another program that creates more readble code that can be easily
edited? How much work is it to write our own wrappers?


Not too much, and practicaly not at all if you want to wrap procedures
(not objects or types):
- marshaslling an argument list from Python to C and from C to Python
takes exactly 1 line of code,
- handling errors takes 2 lines of code (unless you want to do
something fancy with them; I mean just catching an exception and
getting the error message).
- entry in the PyMethodDef is one simple line
Bottomline: you need 5 additional lines of C code per procedure to
make it usable from Python.
Unless you have hundreds of procedures, there is no point in using
special tools to do that. Especially if you need full control over the
results.


My experience too. At least if you are a C programmer.

If it gets hard, it's because the things you wrap do something funky: take
complex memory structures as arguments, have odd resource management, etc.
A tool cannot help you with that anyway.

/Jorgen

--
// Jorgen Grahn <jgrahn@ Ph'nglui mglw'nafh Cthulhu
\X/ algonet.se> R'lyeh wgah'nagl fhtagn!
Sep 3 '05 #7
Thanx for all the answers.

I will write it myself I have done the simple part, wrapping some
functions. Didn't even take 15 minutes so it was really simple.

But I still have to solve the tricky parts. Wrap some complex
structures and pointers so I can use them from Python.

Sep 5 '05 #8

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

Similar topics

2
2888
by: disgracelands | last post by:
I've been looking at using python and it's been going fairly well so far, i can call C from python and python from C fine but now i've hit a snag and i'm wondering how you guys have got around it. I have to initialise python inside my C project so that i can make calls to python modules whenever i need to but i can't create a dll for the project as it's got to produce an exe or at least a lib so that i can execute the initialisation...
75
3910
by: David MacQuigg | last post by:
Seems like we need a simple way to extend Python syntax that doesn't break existing syntax or clash with any other syntax in Python, is easy to type, easy to read, and is clearly distinct from the "base" syntax. Seems like we could put the @ symbol to good use in these situations. Examples: print @(separator = None) x, y, z @x,y:x*x+y*y -- anonymous function
1
1384
by: skull | last post by:
Hi, everyone I wanna know is there any newsgoup(or forums through www) specially for embeded/extend python? thanks in advance -skull
24
3154
by: Jean-Baptiste PERIN | last post by:
Hi, I'm trying to make a windows dll reachable from a python script .. and I'm encountering troubles during link step .. I use "lcc" to compile and link I use python 2.3 under win XP Here's the compile command which seems to work well : -----------------------------------------------------
9
1871
by: Tuvas | last post by:
I am looking for a good tutorial on how to extend python with C code. I have an application built in C that I need to be able to use in Python. I have searched through various sources, starting of course with the Python site itself, and others, but I felt a bit lacking from the Python site, it seems it was only made for those who installed the source distribution, as for the other people... Anyways, thanks for the help!
2
2925
by: mr_gees100_peas | last post by:
Hi, I've been trying for days to make either boost.python or swig to work for me. The one I have gotten the closest to is boost. Note that this is for windows XP. I'm not much of an unix person besides doing simple ls and copy paste. What I have done is to download the boost library: C:\boost_1_34_0 I downloaded the bjam library: C:\boost-jam-3.1.14-1-ntx86
1
2087
by: nimitsis | last post by:
Hello everyone I am trying to use a module , which I have create by using Swig. This module has C code with embedded Python . The relative code follows : // main.c #include "Python.h" #include <stdio.h> int main()
1
3202
by: nimitsis | last post by:
Hello everyone I try to extend Python using a simple C wrapped module . This module includes embedded python code and it is product of Swig . The corresponding files follows : //main.c #include "Python.h" #include <stdio.h> int main() { Py_Initialize();
4
5428
by: spectrumdt | last post by:
Hello. I am trying to extend Python with some C code. I made a trivial "Hello World" program in C that I am trying to wrap in "boilerplate" for inclusion in a Python program. But I can't compile the C code. The C compiler cannot find the required function `Py_BuildValue'. My C code looks like this:
0
9706
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9579
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10319
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10076
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6851
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5520
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5651
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3816
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2990
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.