_PACKAGE in a nested module

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

_PACKAGE in a nested module

Matthew M. Burke-2
If you create a module, call it peanut, with a nested module, say
butter.  And then print(peanut.butter._PACKAGE) the answer you get is
"peanut." with the trailing period.

I would expect the answer to just be "peanut".

Similarly, if you define a module, peanut.butter.sandwich, and then
print(peanut.butter.sandwich._PACKAGE) you get "peanut.butter.".

Is that the intended behavior?

Matt

Reply | Threaded
Open this post in threaded view
|

Re: _PACKAGE in a nested module

Tomas-14
> If you create a module, call it peanut, with a nested module, say butter.
> And then print(peanut.butter._PACKAGE) the answer you get is "peanut." with
> the trailing period.
>
> I would expect the answer to just be "peanut".
>
> Similarly, if you define a module, peanut.butter.sandwich, and then
> print(peanut.butter.sandwich._PACKAGE) you get "peanut.butter.".
>
> Is that the intended behavior?
  This is the correct behaviour.  I think you need ._NAME.
Have you tried it?
  Tomas
Reply | Threaded
Open this post in threaded view
|

Re: _PACKAGE in a nested module

Mike Pall-41
In reply to this post by Matthew M. Burke-2
Hi,

Matthew M. Burke wrote:
> Similarly, if you define a module, peanut.butter.sandwich, and then
> print(peanut.butter.sandwich._PACKAGE) you get "peanut.butter.".
>
> Is that the intended behavior?

Yes, I guess so. Because then you can
  require(_PACKAGE.."jar")
inside the module to get a sibling module, without checking
whether you need to add an intermediate dot or not (_PACKAGE
is "" for the toplevel).

Bye,
     Mike