473,231 Members | 1,740 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,231 software developers and data experts.

Native class methods


Is there an easy way to implement a specific method of a Python class
in C? Like a native method in Java? I would really like to do the
majority of my class code in Python and just do one or two methods
in C.

S.

Oct 9 '07 #1
4 1588
Stefan Arentz wrote:
>
Is there an easy way to implement a specific method of a Python class
in C? Like a native method in Java? I would really like to do the
majority of my class code in Python and just do one or two methods
in C.
ctypes or subclassing C-implemented classes.

Diez
Oct 9 '07 #2
On 09 Oct 2007 17:20:09 +0200, Stefan Arentz <st***********@gmail.comwrote:
>
Is there an easy way to implement a specific method of a Python class
in C? Like a native method in Java? I would really like to do the
majority of my class code in Python and just do one or two methods
in C.

S.
Weave kinda does this - you can use it write inline C code, which it
extracts and compiles for you. (http://scipy.org/Weave)

You might also want to look at Pyrex and/or Cython, which let you
write in a Python-like language that is compiled to C.
(http://www.cosc.canterbury.ac.nz/gre.../python/Pyrex/ and
http://cython.org).

Depending on what you want to do in C, just writing it as a normal
shared library and calling it with ctypes might also be an effective
solution. (in the standard library, as of 2.5)
Oct 9 '07 #3
"Chris Mellon" <ar*****@gmail.comwrites:
On 09 Oct 2007 17:20:09 +0200, Stefan Arentz <st***********@gmail.comwrote:

Is there an easy way to implement a specific method of a Python class
in C? Like a native method in Java? I would really like to do the
majority of my class code in Python and just do one or two methods
in C.

S.

Weave kinda does this - you can use it write inline C code, which it
extracts and compiles for you. (http://scipy.org/Weave)

You might also want to look at Pyrex and/or Cython, which let you
write in a Python-like language that is compiled to C.
(http://www.cosc.canterbury.ac.nz/gre.../python/Pyrex/ and
http://cython.org).

Depending on what you want to do in C, just writing it as a normal
shared library and calling it with ctypes might also be an effective
solution. (in the standard library, as of 2.5)
Yeah I'm really trying to do this without any dependencies on external
libraries. The ctypes way looks interesting but I had really hoped for
something more JNI-like :-/

S.

Oct 9 '07 #4
On 09 Oct 2007 17:45:12 +0200, Stefan Arentz <st***********@gmail.comwrote:
"Chris Mellon" <ar*****@gmail.comwrites:
On 09 Oct 2007 17:20:09 +0200, Stefan Arentz <st***********@gmail.comwrote:
>
Is there an easy way to implement a specific method of a Python class
in C? Like a native method in Java? I would really like to do the
majority of my class code in Python and just do one or two methods
in C.
>
S.
>
Weave kinda does this - you can use it write inline C code, which it
extracts and compiles for you. (http://scipy.org/Weave)

You might also want to look at Pyrex and/or Cython, which let you
write in a Python-like language that is compiled to C.
(http://www.cosc.canterbury.ac.nz/gre.../python/Pyrex/ and
http://cython.org).

Depending on what you want to do in C, just writing it as a normal
shared library and calling it with ctypes might also be an effective
solution. (in the standard library, as of 2.5)

Yeah I'm really trying to do this without any dependencies on external
libraries. The ctypes way looks interesting but I had really hoped for
something more JNI-like :-/

S.
Weave is a runtime solution, but Pyrex and Cython are both compilers
(they compile a Python like language to C, which you the compile into
a single extension module), and ctypes is in the standard library.
Using ctypes would be pretty much just like JNI, except it's dynamic
and not horrible.
Oct 9 '07 #5

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

Similar topics

2
by: Jacob Cohen | last post by:
Under VC7.1, I am trying to wrap a native-C++ DLL that contains C++ objects in a Managed-C++ class library for use in a C# project. I created and compiled the native DLL under VC7.1 as a Win32...
1
by: Bern McCarty | last post by:
What do you make of this? I cannot tell for sure but it almost seems as the the transition thunk to get back from the native bool method to the managed caller is looking at eax and, if any bit is...
9
by: Herby | last post by:
Is possible to have a managed method within a Native(un-managed) class within a \clr project? E.g. class myClass { public: #pragma managed void myMethod(void);
2
by: Haroon_Saeed | last post by:
Hey, I wrote a managed c++ class library in viusal studio 2005. This managed c++ dll calls native C++ methods of an SDK. When I referenced this managed c++ library in a console applciation...
6
by: per9000 | last post by:
An interesting/annoying problem. I created a small example to provoke an exception I keep getting. Basically I have a C-struct (Container) with a function-pointer in it. I perform repeated calls...
1
by: =?Utf-8?B?RmFiaWFu?= | last post by:
Hello, I want to give multiple native classes (in different mixed mode dlls) access to a managed output window (for error messages). Therefore I wrote a native singleton with __declspec...
2
by: Andreas Schmitt | last post by:
Crazy idea but... I think everyone could agree with the statement that the CLI standard Base Class Library is incredibly useful, not to mention the extentions by microsoft and managed directX...
6
by: =?Utf-8?B?RmFiaWFu?= | last post by:
Hello, I have a class hierarchy distributed over 3 native C++ dlls. The base class has a .NET Windows.Form for status output via a gcroot<>. The gcroot is declared private - the sub classes only...
4
by: emtech | last post by:
In Class java.lang.VMSystem there are native methods ,can any body tell me where can I get source code for these native methods? Thanks in advance.
4
by: joes.staal | last post by:
Hi, I know this has been asked earlier on, however, none of the other threads where I looked solved the following problem. 1. I've got a native C++ library (lib, not a dll) with a singleton. 2....
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...

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.