Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Public imports

Reply
Thread Tools

Public imports

 
 
Márcio Faustino
Guest
Posts: n/a
 
      12-08-2008
Hi,

Does Python support public imports instead of the default private?
Something like D's "public import" (see <http://www.digitalmars.com/d/
2.0/module.html>) or even Perl's "export_to_level".

Thanks,
 
Reply With Quote
 
 
 
 
Bruno Desthuilliers
Guest
Posts: n/a
 
      12-08-2008
Márcio Faustino a écrit :
> Hi,
>
> Does Python support public imports instead of the default private?


Python has no notion of "public" or "private" !-)

> Something like D's "public import" (see <http://www.digitalmars.com/d/
> 2.0/module.html>)


Python imports don't work as D imports (as far as I can tell from the
above link). The Python import statement binds imported name - whether
the module object itself[1] or the explicitely[2] or implicitely[3]
specified names from the module object - into the importing module's
namespace.

[1] import some_module
[2] from some_module import some_name
[3] from some_module import *


IOW, if module_b imports module_a and module_c import module_a, module_a
will be accessible in module_c as module_b.module_a. If module_b import
name_x from module_a and module_c imports module_b, name_x will be
accessible in module_c as module_b.name_x. Etc, etc....

HTH



 
Reply With Quote
 
 
 
 
bearophileHUGS@lycos.com
Guest
Posts: n/a
 
      12-08-2008
Márcio Faustino:
> Does Python support public imports instead of the default private?
> Something like D's "public import" (see <http://www.digitalmars.com/d/
> 2.0/module.html>) or even Perl's "export_to_level".


D type system has several big holes, and I am trying to push Walter to
fix some of those, to make it look a little more sane, like for
example the Python module system.
Public imports are often bad.

Bye,
bearophile
 
Reply With Quote
 
bearophileHUGS@lycos.com
Guest
Posts: n/a
 
      12-08-2008
> D type system has several big holes,

I meant "D module system", of course. Sorry.

Bye,
bearophile
 
Reply With Quote
 
Márcio Faustino
Guest
Posts: n/a
 
      12-08-2008
So, no chance of doing this:

# "A.py"
from __future__ import division, with_statement

# "B.py"
from A import *
print 1 / 2

....and printing 0.5, right? Too bad
Thanks!
 
Reply With Quote
 
skip@pobox.com
Guest
Posts: n/a
 
      12-08-2008

Márcio> So, no chance of doing this:
Márcio> # "A.py"
Márcio> from __future__ import division, with_statement

Márcio> # "B.py"
Márcio> from A import *
Márcio> print 1 / 2

Márcio> ...and printing 0.5, right? Too bad

"from __future__ ..." isn't really an import statement in the usual sense of
the term. It affects the byte code compiler immediately and I believe only
when using that syntax. That it actually adds a name to the module's
namespace is not really used (at least, not often).

--
Skip Montanaro - - http://smontanaro.dyndns.org/
 
Reply With Quote
 
Bruno Desthuilliers
Guest
Posts: n/a
 
      12-08-2008
Márcio Faustino a écrit :
> So, no chance of doing this:
>
> # "A.py"
> from __future__ import division, with_statement
>
> # "B.py"
> from A import *
> print 1 / 2
>
> ...and printing 0.5, right?


Nope, but for totally unrelated reasons (cf Skip's anwer).

OTHO, this is valid:

# foo.py
def bar():
return "bar"

# A.py
from foo import bar

# B.py
from A import bar
print bar()


FWIW, this is often used in packages __init__.py to hide the package's
internal organization (or when a module starts to grow too big and has
to be refactored as a package without breaking client code).

HTH
 
Reply With Quote
 
Diez B. Roggisch
Guest
Posts: n/a
 
      12-08-2008
Márcio Faustino schrieb:
> So, no chance of doing this:
>
> # "A.py"
> from __future__ import division, with_statement
>
> # "B.py"
> from A import *
> print 1 / 2
>
> ...and printing 0.5, right? Too bad


Au contraire - *very* good. If it were otherwise, what would happen to
code that _relies_ on / returning an int - some 3rd-party-lib for
example? The same goes for code that contains "with" as variable name or
some such.


Diez
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
microsoft.public.certification, microsoft.public.cert.exam.mcsa, microsoft.public.cert.exam.mcad, microsoft.public.cert.exam.mcse, microsoft.public.cert.exam.mcsd loyola MCSE 4 11-15-2006 02:40 AM
microsoft.public.certification, microsoft.public.cert.exam.mcsa, microsoft.public.cert.exam.mcad, microsoft.public.cert.exam.mcse, microsoft.public.cert.exam.mcsd loyola Microsoft Certification 3 11-14-2006 05:18 PM
microsoft.public.certification, microsoft.public.cert.exam.mcsa, microsoft.public.cert.exam.mcad, microsoft.public.cert.exam.mcse, microsoft.public.cert.exam.mcsd loyola MCSD 3 11-14-2006 05:18 PM
microsoft.public.certification, microsoft.public.cert.exam.mcsa, microsoft.public.cert.exam.mcad, microsoft.public.cert.exam.mcse, microsoft.public.cert.exam.mcsd realexxams@yahoo.com Microsoft Certification 0 05-10-2006 02:35 PM
microsoft.public.dotnet.faqs,microsoft.public.dotnet.framework,microsoft.public.dotnet.framework.windowsforms,microsoft.public.dotnet.general,microsoft.public.dotnet.languages.vb Charles A. Lackman ASP .Net 1 12-08-2004 07:08 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57