Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #81951 > unrolled thread

Re: Style question: Importing modules from packages - 'from' vs 'as'

Started byChris Angelico <rosuav@gmail.com>
First post2014-12-05 08:30 +1100
Last post2014-12-05 08:30 +1100
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: Style question: Importing modules from packages - 'from' vs 'as' Chris Angelico <rosuav@gmail.com> - 2014-12-05 08:30 +1100

#81951 — Re: Style question: Importing modules from packages - 'from' vs 'as'

FromChris Angelico <rosuav@gmail.com>
Date2014-12-05 08:30 +1100
SubjectRe: Style question: Importing modules from packages - 'from' vs 'as'
Message-ID<mailman.16589.1417728663.18130.python-list@python.org>
On Fri, Dec 5, 2014 at 7:56 AM, Wolfgang Maier
<wolfgang.maier@biologie.uni-freiburg.de> wrote:
> On 04.12.2014 19:05, Chris Angelico wrote:
>>
>>
>> With os.path it definitely is. With the actual code in question, it's
>> a Python 2.7 project that mostly uses relative imports - inside
>> package.module1 is "import module2" etc - and I was writing an
>> external script that calls on one of the modules.
>
>
> What ? I'm usually thinking Python 3 not 2 and I'm never sure which Python
> 2.x has backported which feature of 3, but I thought implicit relative
> imports like you seem to describe are not working in 2.7 ?

Hmm, I'm not sure, but certainly it does seem to work that way. Typing
"import foo" from inside a package will import foo.py from the package
directory. I haven't dug into the details of _why_, and if ever the
project shifts to Python 3 (which I would like it to), we might have
to change some of the import lines, but I'd still like to be able to
reference "foo.bar" as meaning the "bar" top-level object in foo.py.

ChrisA

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web