osdir.com


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Get __name__ in C extension module


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" --------
========================================================================