Accessing "variables" in an extension module

arcege at arcege at
Thu Dec 7 16:58:59 CET 2000

Christian Wermuth <christian at> wrote:
: I would like to access "variables" (chars and ints) in a C module
: extension for Python from my Python code. Is that possible?
: If I wanted to improve the example from "Extending and Embedding the
: Python Interpreter" like shown below, what would I need to add to the
: spam.c code?

: import spam
: spam.varstring = "test"
: spam.varint = 5
: spam.system('dir c:')

I'm assuming that you want to have predefined variables and constants.
You might want to look at the section 'Adding "constants"' (which, in
Python, are really variables anyway) in the "Python Extension writing"
document.  That might help you.

The URL for the document is

Remember that modules, whether a C extension or not, are mutable and
you can always add or remove names there.


More information about the Python-list mailing list