Now i need information about interface c and python.Now i call c function from python but i dont know how to return a array from c to python
5 2752 bartonc 6,596
Recognized Expert Expert
Now i need information about interface c and python.Now i call c function from python but i dont know how to return a array from c to python
You'll have to remind me which tool you are using. Also, please post an example of what you are working on.
#include <Python.h>
#include <Numeric/arrayobject.h>
#include <sys/types.h>
#include <stdio.h>
#include <stdlib.h>
#define IDENTITY_DOC "\
This method simply unpacks the Array (so that it could be modified)\
and then returns it unchanged."
static PyObject *identity(PyObj ect *self, PyObject *args)
{
int i,n;
PyObject *input;
PyArrayObject *array;
char *aptr;
if (!PyArg_ParseTu ple(args, "O", &input ))
return NULL;
array = (PyArrayObject *) PyArray_Contigu ousFromObject(i nput, PyArray_INT, 0, 3);
if (array == NULL)
return NULL;
// Compute Size of Array
if(array->nd == 0)
n = 1;
else {
n = 1;
for(i=0;i<array->nd;i++)
n = n * array->dimensions[i];
}
aptr=(char*)(ar ray->data);
// Do Your Array Operation(s)
// Return the result
return PyArray_Return( array);
}
this is my wrapper code in c.in this code finally i was return a array (pyArray_Return (array).so how can i get the return value in python
And also i had Python2.5
Now i need information about interface c and python.Now i call c function from python but i dont know how to return a array from c to python
this is my samplecode -
#include <Python.h>
-
#include <Numeric/arrayobject.h>
-
#include <sys/types.h>
-
#include <stdio.h>
-
#include <stdlib.h>
-
-
#define IDENTITY_DOC "\
-
This method simply unpacks the Array (so that it could be modified)\
-
and then returns it unchanged."
-
static PyObject *identity(PyObject *self, PyObject *args)
-
{
-
int i,n;
-
PyObject *input;
-
PyArrayObject *array;
-
char *aptr;
-
-
if (!PyArg_ParseTuple(args, "O", &input ))
-
return NULL;
-
array = (PyArrayObject *) PyArray_ContiguousFromObject(input, PyArray_INT, 0, 3);
-
if (array == NULL)
-
return NULL;
-
-
// Compute Size of Array
-
if(array->nd == 0)
-
n = 1;
-
else {
-
n = 1;
-
for(i=0;i<array->nd;i++)
-
n = n * array->dimensions[i];
-
}
-
-
aptr=(char*)(array->data);
-
-
// Do Your Array Operation(s)
-
-
// Return the result
-
return PyArray_Return(array);
-
}
-
-
this is my wrapper code in c.in this code finally i was return a array (pyArray_Return (array).so how can i get the return value in python
And also i had Python2.5
Did you ever figure this out? I'm new to the forum, but I have the answer if you still need it.
bartonc 6,596
Recognized Expert Expert
Did you ever figure this out? I'm new to the forum, but I have the answer if you still need it.
Hello, card. Welcome to the Python Forum on TheScripts.
Please feel free to update any posts that may assist others in the future.
We appreciate any contribution and hope to be able to assist you with you queries.
Thanks for joining.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: MangoMan |
last post by:
Hi there,
Currently i am having a problem with python's array class.
I am reading 3 arrays from a file (self.buffer32, self.buffer16,
self.buffer8 from self.fs) :
# ...
self.Allocated32 = offset16
self.Allocated16 = offset8-offset16
|
by: Martin DeMello |
last post by:
It seems to be a fairly common pattern for an object-modifying method to
return None - however, this is often quite inconvenient.
For instance
def f(lst1, lst2):
g((lst1 + lst2).reverse()) # doesn't work!
you need to say
|
by: Bo Peng |
last post by:
Dear list,
I am writing a Python extension module that needs a way to expose pieces
of a big C array to python. Currently, I am using NumPy like the following:
PyObject* res = PyArray_FromDimsAndData(1, int*dim, PyArray_DOUBLE,
char*buf);
Users will get a Numeric Array object and can change its values (and
actually change the underlying C array).
|
by: Java and Swing |
last post by:
Hi,
I have been posting about writing a C extension for Python...so far,
so good. At least for the "simple" functions that I need to wrap.
Ok, my c function looks like...
MY_NUM *doNumberStuff(const char *in, const char *x) { ... }
MY_NUM is defined as, typedef unsigned long MY_NUM; (not sure if that
matters, or can i just create a wrapper which handles longs?)
|
by: Grzegorz Smith |
last post by:
Hi all. I'm trying get data from text field in MySQl 5.0 with my National
characters. Data are stored in utf8 encodings. Here is the script:
import MySQLdb, MySQLdb.cursors
conn = MySQLdb.connect(host='localhost', user='root', passwd='123456',
db='profile_locale')
c = conn.cursor(MySQLdb.cursors.DictCursor)
c.execute("SET CHARACTER SET utf8")
c.execute("SELECT string_value FROM lang_pl_pl WHERE id=8")
row = c.fetchone()
print row
| |
by: bruce |
last post by:
hi...
i'm trying to deal with multi-dimension lists/arrays
i'd like to define a multi-dimension string list, and then manipulate the
list as i need... primarily to add lists/information to the 'list/array' and
to compare the existing list information to new lists
i'm not sure if i need to import modules, or if the base python install i
have is sufficient. an example, or pointer to examples would be good...
|
by: Boris Mok |
last post by:
Hi all,
I'm doing a function which needs return an arrary -- or more specially a
dictionary data type.
I have a sample like this
def AFC():
v = 1
return v
|
by: Santiago Romero |
last post by:
Hi :)
First of all, I must apologize for my poor english :)
I'm starting with python and pygame and for testing (and learning)
purposes I wrote an small "Map Editor" for a small game project I'm
going to start next month.
The tilemap editor is working fine, but reading Guido's Van Rossum
PYTHON TUTORIAL I found that my game map is "wasting" memory by using
|
by: J. Peng |
last post by:
what's the difference between an array and a list in python?
I see list has all features of array in C or perl.
so please tell me.thanks.
|
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...
|
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,...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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,...
|
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...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
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...
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |