Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #104226
| From | Chris Angelico <rosuav@gmail.com> |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | Re: A mistake which almost went me mad |
| Date | 2016-03-08 03:40 +1100 |
| Message-ID | <mailman.28.1457368833.10335.python-list@python.org> (permalink) |
| References | (1 earlier) <CAGuvt92tsr8hN+XnYB=FtmAXTDuM198FY92Sjjtw=P2QaVwjUg@mail.gmail.com> <20160303054822.342fb513@bigbox.christie.dr> <CAHVvXxRqkpHiWjiiUgi5JDgbMOdceTVEGBQzLP+dDy4dBuG3LQ@mail.gmail.com> <20160303125053.79e95bde@bigbox.christie.dr> <CALwzidmxMHF-jojjMbfT8g9V+Etngyf1qnnS+siCgWunamnqUw@mail.gmail.com> |
On Tue, Mar 8, 2016 at 3:19 AM, Ian Kelly <ian.g.kelly@gmail.com> wrote: > On Thu, Mar 3, 2016 at 11:50 AM, Tim Chase > <python.list@tim.thechases.com> wrote: >> I think that relative imports should ameliorate this, as I usually >> hit it when I'm using smtplib which in turn imports "email" (and, in >> 2.x when it found my local email.py would crash and burn). If it used >> a relative import that forced it to find the one in the stdlib, it >> should(?) prevent it from finding my local version first. > > Relative imports only work inside packages. You can't use a relative > import to import one top-level module from another. > > Besides, the relative import doesn't help to disambiguate in this > case. The absolute path of the stdlib email module is "email". The > absolute path of the module in your CWD is also "email". Why should a > relative import prefer one over the other? So I would think that even > if it worked, it would still just end up importing the first one it > finds on your sys.path. So the solution is to treat the current directory as a pseudo-package. It'd be a backward-incompatible change, so it would need to be explicitly invoked. Something like: python3 -p somefile.py which would pretend to create an __init__.py in the current directory, change to the parent, and "from dirname import somefile". I mentioned this one time before, but it got kinda missed; I think I'll reraise it on python-ideas. It's a protection on par with not having the current directory in $PATH. ChrisA
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
A mistake which almost went me mad "ast" <nomail@invalid.com> - 2016-03-03 11:21 +0100
Re: A mistake which almost went me mad Chris Angelico <rosuav@gmail.com> - 2016-03-03 21:31 +1100
Re: A mistake which almost went me mad Nick Sarbicki <nick.a.sarbicki@gmail.com> - 2016-03-03 10:43 +0000
Re: A mistake which almost went me mad Tim Golden <mail@timgolden.me.uk> - 2016-03-03 10:48 +0000
Re: A mistake which almost went me mad Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2016-03-04 19:19 +1300
Re: A mistake which almost went me mad Steven D'Aprano <steve@pearwood.info> - 2016-03-03 23:57 +1100
Re: A mistake which almost went me mad Tim Chase <python.list@tim.thechases.com> - 2016-03-03 05:48 -0600
Re: A mistake which almost went me mad Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2016-03-03 16:29 +0000
Re: A mistake which almost went me mad Rob Gaddi <rgaddi@highlandtechnology.invalid> - 2016-03-03 17:53 +0000
Re: A mistake which almost went me mad Tim Chase <python.list@tim.thechases.com> - 2016-03-03 12:50 -0600
Re: A mistake which almost went me mad Ian Kelly <ian.g.kelly@gmail.com> - 2016-03-07 09:19 -0700
Re: A mistake which almost went me mad Random832 <random832@fastmail.com> - 2016-03-07 11:28 -0500
Re: A mistake which almost went me mad Chris Angelico <rosuav@gmail.com> - 2016-03-08 03:40 +1100
Re: A mistake which almost went me mad Rick Johnson <rantingrickjohnson@gmail.com> - 2016-03-09 08:34 -0800
Re: A mistake which almost went me mad Rustom Mody <rustompmody@gmail.com> - 2016-03-09 22:13 -0800
Re: A mistake which almost went me mad Rick Johnson <rantingrickjohnson@gmail.com> - 2016-03-10 16:54 -0800
csiph-web