Get __name__ in C extension module
Barry Scott
barry at barrys-emacs.org
Mon Oct 7 03:06:07 EDT 2019
> On 7 Oct 2019, at 04:34, MRAB <python at mrabarnett.plus.com> wrote:
>
> 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.
You could have 2 modules that share code.
But you cannot init the same module twice.
Barry
>
> --
> https://mail.python.org/mailman/listinfo/python-list <https://mail.python.org/mailman/listinfo/python-list>
More information about the Python-list
mailing list