[BangPypers] Favorite tips/techniques

Saju M sajuptpm at gmail.com
Fri Sep 13 09:40:29 CEST 2013


Saager,
As per python module-import semantics, sub-modules don't end up as names in
the
package-module[*] unless explicitly added.

I didn't get it, what you mean by package-module[*] ?.

--------------------------

One simple test.

dir(json) showing the module "tool" after "from json import tool", but that
module not in json.__all__ list.

>>>
>>>* import json*
>>>
>>>
>>> *dir(json)*
['JSONDecoder', 'JSONEncoder', '__all__', '__author__', '__builtins__',
'__doc__', '__file__', '__name__', '__package__', '__path__',
'__version__', '_default_decoder', '_default_encoder', 'decoder', 'dump',
'dumps', 'encoder', 'load', 'loads', 'scanner']
>>>
>>>
>>>* json.__all__*
['dump', 'dumps', 'load', 'loads', 'JSONDecoder', 'JSONEncoder']
>>>
>>>
>>> *from json import tool*
>>>
>>>
>>> dir(json)
['JSONDecoder', 'JSONEncoder', '__all__', '__author__', '__builtins__',
'__doc__', '__file__', '__name__', '__package__', '__path__',
'__version__', '_default_decoder', '_default_encoder', 'decoder', 'dump',
'dumps', 'encoder', 'load', 'loads', 'scanner', *'tool'*]
>>>
>>>
>>> *json.__all__*
['dump', 'dumps', 'load', 'loads', 'JSONDecoder', 'JSONEncoder']
>>>
>>>

Regards
Saju Madhavan
+91 09535134654


On Fri, Sep 13, 2013 at 8:25 AM, Noufal Ibrahim <noufal at nibrahim.net.in>wrote:

> Saager Mhatre <saager.mhatre at gmail.com> writes:
>
> > On Tue, Sep 10, 2013 at 4:54 PM, Noufal Ibrahim <noufal at nibrahim.net.in
> >wrote:
> >
> >> Saju M <sajuptpm at gmail.com> writes:
> >> [...]
> >>
> >
> >> > * Why dir(json) not showing "tool" ??
> >>
> >> Because of the __all__ variable in the module.
> >> http://docs.python.org/2/tutorial/modules.html
> >>
> >
> > Noufal,
> > Well, not quite, right? I posit it's basically because as per python
> > module-import semantics, sub-modules don't end up as names in the
> > package-module[*] unless explicitly added, right?
>
> Yes. I think that's more accurate. Mea culpa.
>
> [...]
>
>
> --
> Cordially,
> Noufal
> http://nibrahim.net.in
> _______________________________________________
> BangPypers mailing list
> BangPypers at python.org
> https://mail.python.org/mailman/listinfo/bangpypers
>


More information about the BangPypers mailing list