Re: Get __name__ in C extension module

2019-10-08 Thread Barry Scott
> On 7 Oct 2019, at 00:44, Ian Pilcher wrote: > > On 10/6/19 12:55 PM, Barry Scott wrote: >> Then the answer to your question is simple. Do it in python and passt >> logger into the C++ module. > > Funny thing, that's exactly where I started this journey. I couldn't > figure out how to get t

Re: Get __name__ in C extension module

2019-10-07 Thread Ian Pilcher
On 10/7/19 2:09 AM, Barry Scott wrote: I meant pass in the specific named logger that you C code will use. Right, but I'm assuming that your C/C++ code will receive the logger object by calling PyArg_ParseTuple (or similar), and I further assume that you want to validate that the object actuall

Re: Get __name__ in C extension module

2019-10-07 Thread Barry Scott
> On 7 Oct 2019, at 00:44, Ian Pilcher wrote: > > On 10/6/19 12:55 PM, Barry Scott wrote: >> Then the answer to your question is simple. Do it in python and passt >> logger into the C++ module. > > Funny thing, that's exactly where I started this journey. I couldn't > figure out how to get t

Re: Get __name__ in C extension module

2019-10-07 Thread Barry Scott
> On 7 Oct 2019, at 04:34, MRAB 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 b

Re: Get __name__ in C extension module

2019-10-06 Thread MRAB
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 usi

Re: Get __name__ in C extension module

2019-10-06 Thread Ian Pilcher
On 10/6/19 12:55 PM, Barry Scott wrote: Then the answer to your question is simple. Do it in python and passt logger into the C++ module. Funny thing, that's exactly where I started this journey. I couldn't figure out how to get the logging.Logger type object, so that I could use a "O!" format

Re: Get __name__ in C extension module

2019-10-06 Thread Ian Pilcher
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

Re: Get __name__ in C extension module

2019-10-06 Thread Barry Scott
> On 5 Oct 2019, at 18:55, Ian Pilcher wrote: > > On 10/4/19 4:30 PM, Ian Pilcher wrote: >> Ideally, I would pass my existing Logging.logger object into my C >> function and use PyObject_CallMethod to call the appropriate method on >> it (info, debug, etc.). > > As I've researched this furthe

Re: Get __name__ in C extension module

2019-10-06 Thread MRAB
On 2019-10-06 15:48, Ian Pilcher wrote: On 10/5/19 12:55 PM, Ian Pilcher wrote: This is straightforward, except that I cannot figure out how to retrieve the __name__. Making progress. I can get a __name__ value with: PyDict_GetItemString(PyEval_GetGlobals(), "__name__") I say "a __name_

Re: Get __name__ in C extension module

2019-10-06 Thread Ian Pilcher
On 10/5/19 12:55 PM, Ian Pilcher wrote: This is straightforward, except that I cannot figure out how to retrieve the __name__. Making progress. I can get a __name__ value with: PyDict_GetItemString(PyEval_GetGlobals(), "__name__") I say "a __name__ value" because the returned value is actu