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

Get __name__ in C extension module

On 2019-10-07 00:38, Ian Pilcher wrote:
> 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.
Can an extension module be instantiated twice? If so, would they share 
static variables? If they don't, then it's not a problem.