Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

importing pkg.sub as other.sub

I don't have this problem, but it came to my mind while I was working on a related issue. Let's have:

logging = 'something'  # bad naming decision
import logging as lg   # using a different name

How do you import logging.config as lg.config without overwriting the original logging?

After some testing I found this:

import logging.config as _  # any unused name

But is it really correct? Are there better solutions?

like image 256
VPfB Avatar asked Dec 18 '25 13:12

VPfB


1 Answers

How about doing something like this ?

import logging as lg
from logging import config

After this both config and lg.config refer to logging.config.

In [3]: config
Out[3]: <module 'logging.config' from 'C:\\Anaconda3\\lib\\logging\\config.py'>

In [4]: lg.config
Out[4]: <module 'logging.config' from 'C:\\Anaconda3\\lib\\logging\\config.py'>
like image 179
PaW Avatar answered Dec 20 '25 17:12

PaW



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!