Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #101343 > unrolled thread
| Started by | Robert <rxjwg98@gmail.com> |
|---|---|
| First post | 2016-01-07 08:50 -0800 |
| Last post | 2016-01-08 04:00 +1100 |
| Articles | 2 — 2 participants |
Back to article view | Back to comp.lang.python
What meaning is 'from . import' Robert <rxjwg98@gmail.com> - 2016-01-07 08:50 -0800
Re: What meaning is 'from . import' Chris Angelico <rosuav@gmail.com> - 2016-01-08 04:00 +1100
| From | Robert <rxjwg98@gmail.com> |
|---|---|
| Date | 2016-01-07 08:50 -0800 |
| Subject | What meaning is 'from . import' |
| Message-ID | <5cc5c4f2-ecc9-4ae4-b2d4-92a234012ae7@googlegroups.com> |
Hi, I see the following code. After searching around, I still don't know the meaning of '.'. Could you tell me that ? Thanks, from . import _hmmc from .utils import normalize
[toc] | [next] | [standalone]
| From | Chris Angelico <rosuav@gmail.com> |
|---|---|
| Date | 2016-01-08 04:00 +1100 |
| Message-ID | <mailman.51.1452186009.2305.python-list@python.org> |
| In reply to | #101343 |
On Fri, Jan 8, 2016 at 3:50 AM, Robert <rxjwg98@gmail.com> wrote: > Hi, > > I see the following code. After searching around, I still don't know the > meaning of '.'. Could you tell me that ? Thanks, > > > > > > from . import _hmmc > from .utils import normalize That's called a package-relative import. https://www.python.org/dev/peps/pep-0328/ If you create a package called (let's be really creative here) "package", an external script could do this: from package import _hmmc from package.utils import normalize Within the package, you can say "from myself import stuff". It's exactly the same thing, only it doesn't repeat the package name. If you think of a package as a directory (which it often will be anyway), the dot is similar to the common notation for "current directory". ChrisA
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web