Path: csiph.com!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail From: Chris Angelico Newsgroups: comp.lang.python Subject: Re: What meaning is 'from . import' Date: Fri, 8 Jan 2016 04:00:06 +1100 Lines: 29 Message-ID: References: <5cc5c4f2-ecc9-4ae4-b2d4-92a234012ae7@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Trace: news.uni-berlin.de MLUrfPvexscvJWJ63gMpFQ6jJh8Owviyd2N4ieumrgWg== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.016 X-Spam-Evidence: '*H*': 0.97; '*S*': 0.00; 'received:209.85.223': 0.03; 'cc:addr:python-list': 0.09; 'jan': 0.11; 'package,': 0.13; '"current': 0.16; '2016': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'subject:import': 0.16; 'wrote:': 0.16; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; 'am,': 0.23; 'code.': 0.23; 'this:': 0.23; 'thanks,': 0.24; 'import': 0.24; 'header:In- Reply-To:1': 0.24; 'script': 0.25; "doesn't": 0.26; '(which': 0.26; 'external': 0.27; 'fri,': 0.27; 'message- id:@mail.gmail.com': 0.27; 'notation': 0.29; 'url:peps': 0.29; 'url:python': 0.33; 'common': 0.33; 'similar': 0.33; 'received:google.com': 0.35; 'could': 0.35; 'robert': 0.35; 'url:dev': 0.35; 'url:org': 0.36; 'received:209.85': 0.36; 'subject:: ': 0.37; 'really': 0.37; 'say': 0.37; 'received:209': 0.38; 'hi,': 0.38; 'subject:from': 0.39; 'still': 0.40; 'called': 0.40; 'within': 0.64; 'repeat': 0.67; 'around,': 0.84; 'chrisa': 0.84; 'subject: . ': 0.84; 'to:none': 0.91; 'thing,': 0.93 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type; bh=DkBuH8oGnxlLsKAJlqRP85k8zaD9RqUORAlHmKu8Q48=; b=NcKZwWEaTWJdBCqlQH3Xo7ta1z7JVOnOyqMekQxuCkQYFydlNW5mez9eTyXRivtiy2 YVwZzQ5Dx1gMERaiIE1KRRrrxzbX5CoQocDihZYWBLg6LKToqaLUJu5pZVhVazspd0Cs ts30Fz9Si8z7LuYwwBVNXp2kShBsiXWmN70QddrrtQT8isLPIBmXFoiOF3ueHRYA8aOZ d6X+ydtFW1PVxaC93ZhnWbpKVL/j53eCotudswZSBYpMwwAP/JKuXmQPFcph6tvLR68J vwjLg+Q3NgsEOg+e2sNIVozpGDmlp0TZ2pNEc2SAfJ3LP4FkvPuv4Nix7WupoRE8wUN5 q/ow== X-Received: by 10.107.40.76 with SMTP id o73mr35562155ioo.157.1452186006117; Thu, 07 Jan 2016 09:00:06 -0800 (PST) In-Reply-To: <5cc5c4f2-ecc9-4ae4-b2d4-92a234012ae7@googlegroups.com> X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Xref: csiph.com comp.lang.python:101345 On Fri, Jan 8, 2016 at 3:50 AM, Robert 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