[Python-ideas] Allow from foo import bar*

Joshua Landau joshua at landau.ws
Thu Oct 3 21:59:42 CEST 2013


On 3 October 2013 19:43, Giampaolo Rodola' <g.rodola at gmail.com> wrote:
>> Hm. Why not just use "import socket" and then use "socket.AF_<whatever>"?
>
> That's what I usually do as well (because explicit is better than implicit)
> but from my understanding when it comes to constants it is generally not
> considered a bad practice to import them directly into the module namespace.
> I guess my specific case is bit different though.
> I have all these constants defined in a _linux.py submodule which I import
> from __init__.py in order to expose them publicly.
> And this is how I do that:
>
>     # Linux >= 2.6.36
>     if _psplatform.HAS_PRLIMIT:
>         from psutil._pslinux import (RLIM_INFINITY, RLIMIT_AS, RLIMIT_CORE,
>                                      RLIMIT_CPU, RLIMIT_DATA, RLIMIT_FSIZE,
>                                      RLIMIT_LOCKS, RLIMIT_MEMLOCK,
...
>
> In *this specific case* a "from _psplatform import RLIM*" would have solved
> my problem nicely.

Or we change the module such that we can do

    from psutil._pslinux import RLIMIT

and then use RLIMIT.CORE, RLIMIT.CPU, RLIMIT.LOCKS, etc.


More information about the Python-ideas mailing list