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


Groups > comp.lang.python > #41953

Re: import in Python3.3

Date 2013-03-26 21:16 +0000
From Phil Connell <pconnell@gmail.com>
Subject Re: import in Python3.3
References <kio19e$5e2$1@ger.gmane.org> <mailman.3722.1364281502.2939.python-list@python.org> <2b893e00-8fac-4733-b07d-2041af850540@googlegroups.com>
Newsgroups comp.lang.python
Message-ID <mailman.3777.1364332827.2939.python-list@python.org> (permalink)

Show all headers | View raw


On Tue, Mar 26, 2013 at 08:37:00AM -0700, rocky wrote:
> And again, I get the impression that for the use case asked about, there isn't much ambiguity. If I am in mypackage.foo and I want to access mypackage.collections I should be able to say something like that without ambiguity or that much inference or directory searching. If mypackage.colletions is not found inside the same directory as mypackage.foo, often I DON'T WANT Python to helpfully go searching around other places for it which sys.path will do. Instead what I probably want is Python to give me an error. 
> 
> So again I come to import_relative, http://code.google.com/p/pyimport-relative/.  And again, I wish this package didn't have to exist.

What's wrong with PEP 328 relative imports?

In mypackage.foo, use

    from . import collections

to import mypackage.collections.


This has been part of the language since ~2.5

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Re: import in Python3.3 Terry Reedy <tjreedy@udel.edu> - 2013-03-26 03:04 -0400
  Re: import in Python3.3 rocky <rocky@gnu.org> - 2013-03-26 08:37 -0700
    Re: import in Python3.3 Phil Connell <pconnell@gmail.com> - 2013-03-26 21:16 +0000
    Re: import in Python3.3 Rocky Bernstein <rocky@gnu.org> - 2013-03-26 18:24 -0400
    Re: import in Python3.3 Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-03-26 23:06 +0000
      Re: import in Python3.3 rocky <rocky@gnu.org> - 2013-03-26 17:33 -0700
  Re: import in Python3.3 rocky <rocky@gnu.org> - 2013-03-26 08:37 -0700

csiph-web