Accessing "variables" in an extension module

arcege at shore.net arcege at shore.net
Thu Dec 7 10:58:59 EST 2000


Christian Wermuth <christian at integration-x.com> 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
<URL: http://starship.python.net/crew/arcege/extwriting/pyext.html>

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

  -Arcege




More information about the Python-list mailing list