Skip to Content
Python: Essential Reference, Third Edition
book

Python: Essential Reference, Third Edition

by David Beazley
February 2006
Intermediate to advanced content levelIntermediate to advanced
648 pages
14h 53m
English
Sams
Content preview from Python: Essential Reference, Third Edition

Calling Python from C

Sometimes it’s useful to call Python functions from C programs. To do this, the following functions can be used:

						PyObject *PyEval_CallObject(PyObject
						*func,
						PyObject
						*args)

Calls func with arguments args. func is a Python callable object (function, method, class, and so on). args is a tuple of arguments.

						PyObject *PyEval_CallObjectWithKeywords(PyObject
						*func,
						PyObject
						*args,
						PyObject
						*kwargs)

Calls func with positional arguments args and keyword arguments kwargs. func is a callable object, args is a tuple, and kwargs is a dictionary.

The following example illustrates the use of these functions:

 /* Call a python function */ PyObject *func; /* Callable object. */ PyObject *args; PyObject *result; int arg1, arg2; func = ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Python: Essential Reference

Python: Essential Reference

David M. Beazley

Publisher Resources

ISBN: 0672328623Purchase book