Calling a python method from C++ has the following signature:
PyObject *
PyObject_CallMethod(PyObject *self, char *method_name,
char *arg_format, ...);
I'm having trouble figuring out how to declare self.
Let's say my python file is called stuff.py and is like the following,
doMath() is defined in stuff.py and is not part of any class:
#stuff.py
def doMath():
val = val + 1
In C++, I think my codes should be like the following:
PyObject *resultObj = PyObject_CallMethod( self, "doMath", "");
What do I put for self? Any help please? 2 4590
"la********@gmail.com" wrote: Calling a python method from C++ has the following signature:
PyObject * PyObject_CallMethod(PyObject *self, char *method_name, char *arg_format, ...);
I'm having trouble figuring out how to declare self.
Reading the C API documentation might provide the clues you're
looking for:
PyObject* PyObject_CallMethod(PyObject *o, char *method, char *format, ...)
Return value: New reference.
Call the method named method of object o with a variable number of C arguments.
/.../ This is the equivalent of the Python expression "o.method(args)".
What is the object? What method are you calling? What arguments
are you passing in?
Let's say my python file is called stuff.py and is like the following, doMath() is defined in stuff.py and is not part of any class:
#stuff.py
def doMath(): val = val + 1
That's a function, not an object method.
In C++, I think my codes should be like the following:
PyObject *resultObj = PyObject_CallMethod( self, "doMath", "");
What do I put for self? Any help please?
CallMethod is used to call a method on a given object. To call a callable object
(such as a function), other callable object, use PyObject_Call (or CallObject
or CallFunction). See the C API documentation for details.
</F>
Hi, Calling a python method from C++ has the following signature:
PyObject * PyObject_CallMethod(PyObject *self, char *method_name, char *arg_format, ...);
I'm having trouble figuring out how to declare self.
Let's say my python file is called stuff.py and is like the following, doMath() is defined in stuff.py and is not part of any class:
#stuff.py
def doMath(): val = val + 1
In C++, I think my codes should be like the following:
PyObject *resultObj = PyObject_CallMethod( self, "doMath", "");
What do I put for self? Any help please?
it looks like you are confusing methods (bound to class objects) and
functions (bound to modules). if your doMath is a function defined in
a module, use
PyObject* PyObject_Call(PyObject *callable_object, PyObject *args,
PyObject *kw)
i.e.
PyObject resultObj = PyObject_Call(doMath,NULL,NULL);
If, however, doMath is declared as a class-bound method, you have to use
PyObject_CallMethod() with a pointer to an instance of this class as the
first argument.
Cheers,
- harold -
--
Je me suis enfermé dans mon amour -- je rève.
-- Paul Eluard This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Carlos Ribeiro |
last post by:
Hello all,
I'm posting this to the list with the intention to form a group of
people interested in this type of solution. I'm not going to spam the
list with it, unless for occasional and...
|
by: fred |
last post by:
I don't know if I'm doing this correctly. I have a little programming
experience in python, c++ and some others but this is my first time with
javascript. I'm trying have my website detect the...
|
by: MLH |
last post by:
I have a form module that starts out something like this...
Option Compare Database 'Use database order for string comparisons
.....
Then there's a line like this in it...
Public Const...
|
by: Steve Jorgensen |
last post by:
Many of the regulars here have explained that declaring variables using As New
.... is a bad idea, and some have given some good explanations, but I wanted
add one more demonstration to the mix. ...
|
by: G Patel |
last post by:
Hi,
If I want to call functions that don't return int without declaring
them, will there be any harm?
I only want to assign the function(return value) to the type that it
returns, so I don't...
|
by: arekkusu |
last post by:
Hello, I have the following problem:
when declaring hex data in C, you typically do something like:
const char = {0xde, 0xad, 0xbe, 0xef, 0x01, 0x02, 0x03, 0x04 ... };
This is quite verbose...
|
by: Maarten Terlingen |
last post by:
Sample:
ClassA: ClassB
ClassB: ClassC
ClassA x = new Class C
I want to know the declaring type of C.
x.GetType() returns C
x.GetType().BaseType returns B
x.GetType().BaseType.BaseType...
|
by: Huayang Xia |
last post by:
I am trying to use PyObject_CallMethod. It needs a format string to
specify what are the followed arguments. Is it possible to use a
PyObject* as an argument?
Where can I find the spec for the...
|
by: =?ISO-8859-1?Q?Janne_H=E4rk=F6nen?= |
last post by:
Hello,
Is there a simple way to resolve declaring class of a method at runtime ?
Consider this simple example:
$ python
Python 2.5.1 (r251:54863, May 18 2007, 16:56:43)
on cygwin
Type...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
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...
|
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...
| |