Get __name__ in C extension module

Ian Pilcher arequipeno at gmail.com
Sun Oct 6 19:38:19 EDT 2019


On 10/6/19 11:55 AM, MRAB wrote:
> Don't you already have the module's name? You have to specify it in the 
> PyModuleDef struct that you pass to PyModule_Create.

I do.  Perhaps I'm trying to be too Pythonic, but there's so much advice
out there about using getLogger(__name__) in Python code, rather than
hardcoding the name.  I've been trying to follow that pattern in my
extension module.

> Calling PyModule_Create returns a reference to the module, and you can 
> get its namespace dict with PyModule_GetDict(...).

Right.  I have that in my module init function, but how do I access that
later in one of my extension functions?  The only thing I can think of
would be to save it in a static variable, but static variables seem to
be a no-no in extensions.

-- 
========================================================================
Ian Pilcher                                         arequipeno at gmail.com
-------- "I grew up before Mark Zuckerberg invented friendship" --------
========================================================================




More information about the Python-list mailing list