logging = logging.getLogger(__name__)

Stephen Hansen me+list/python at ixokai.io
Tue Jun 15 12:26:00 EDT 2010


On 6/15/10 9:03 AM, genkuro wrote:
> I'm coming to Python from Java.  I'm still getting a feel for scoping
> limits.  For the sake of curiosity, is there another way to refer to a
> package besides name?

The only way to refer to anything is by its name -- or, from a name and
through subscript/dot notation if you've stored something in a container.

But a package (and anything else) can have many names, and it really has
no idea what they are.

You can do "import logging as logging_package" which is just a shortcut for:

    import logging
    logging_package = logging
    del logging

And such.

That said: The frameworks I've seen that shadow the global 'logging'
package with a specific logger do so somewhat on purpose (though I find
the practice slightly dubious), so that naive code which previously just
used the general root logger would work with the more specific one
seamlessly.

But such frameworks usually also have a setup/environment sort of file
where this is not done, and that's where things like adding handlers
belongs.

Just as an aside.

Renaming "logging = ..." to "logger = ..." is probably a better solution
anyways :)

-- 

   Stephen Hansen
   ... Also: Ixokai
   ... Mail: me+list/python (AT) ixokai (DOT) io
   ... Blog: http://meh.ixokai.io/

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 487 bytes
Desc: OpenPGP digital signature
URL: <http://mail.python.org/pipermail/python-list/attachments/20100615/240310e4/attachment-0001.sig>


More information about the Python-list mailing list