Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Ian Kelly Newsgroups: comp.lang.python Subject: Re: importing: what does "from" do? Date: Thu, 21 Jan 2016 08:59:39 -0700 Lines: 47 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Trace: news.uni-berlin.de LAxtsdoi/V3xVXHTBaUL7QU+OXqaQhyyIxEE4z+XTI0Q== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'received:209.85.223': 0.03; 'none,': 0.05; '21,': 0.07; 'defines': 0.07; 'debugger': 0.09; 'defined,': 0.09; 'defined.': 0.09; 'nameerror:': 0.09; 'jan': 0.11; 'package,': 0.13; 'importing': 0.15; 'thu,': 0.15; "'int'": 0.16; '2016': 0.16; 'caches': 0.16; 'ls:': 0.16; 'module?': 0.16; 'project)': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'sys.modules': 0.16; 'sys.path': 0.16; 'wrote:': 0.16; "wouldn't": 0.16; '>>>': 0.20; 'first,': 0.20; 'am,': 0.23; 'defined': 0.23; 'this:': 0.23; 'tried': 0.24; 'import': 0.24; 'header:In-Reply-To:1': 0.24; 'module': 0.25; "doesn't": 0.26; 'message-id:@mail.gmail.com': 0.27; "skip:' 10": 0.28; 'project:': 0.29; 'subject:what': 0.29; 'relative': 0.30; 'probably': 0.31; 'point': 0.33; 'problem': 0.33; 'file': 0.34; 'running': 0.34; 'received:google.com': 0.35; 'something': 0.35; 'but': 0.36; 'received:209.85': 0.36; 'loaded': 0.36; 'subject:" ': 0.36; 'to:addr:python-list': 0.36; 'subject:?': 0.36; 'subject:: ': 0.37; 'really': 0.37; 'received:209': 0.38; 'anything': 0.38; 'means': 0.39; 'why': 0.39; 'subject:from': 0.39; 'to:addr:python.org': 0.40; 'some': 0.40; 'skip:u 10': 0.61; 'side': 0.62; '(that': 0.63; 'smith': 0.76; 'miss.': 0.84; 'to:name:python': 0.84; 'shadow': 0.91; '***': 0.95 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; bh=PO/ZmP+yoVhWgtOScxCi7tBgzJMqhskUoZnYuslaqvg=; b=UZocfIvfcQ8nUkB0tovqZUUkeqAceMAtgruRuE6I+DeJvlro4HOiGjFuH8F5EFHo6a uFrUqxF2jpicZZh0Pyl8ecjRrkUsstT09QpcU/nmcfRY3iXtz0ZHA2FYCf52uSnuMu9w gHZxVzzq/b4AnKMkl1F7gEU2BXufsw03dTT5CBnjMr5Mw5qjUVpIzFfRyqgE/cjDyGI1 QG6I2QzxCGVdabfjh5WhuwI4r34mfTguV0wLJY8ZuCff2uCqGFI2atrj3QsQLzo0LnFV o6HISl/Z8rdwI/0Ud2iVvfInmTcknfEwL9D2NSlDLN3rkZOMAJ6zk49ji0KV2H0prVOJ 2hJg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:content-type; bh=PO/ZmP+yoVhWgtOScxCi7tBgzJMqhskUoZnYuslaqvg=; b=QfGaKFV799CmYXf1qIvaBY22yqCz5+rRkkuExWMantaMnwa24qJbJAphoz5K6LTu0Q oznpN1/qnzp+MGe2jAf5NppfitkW9EAyjrEQ3TQDjIcPjSG0sL8YyjYd/17OqlXh4FLg XUAygYzaIq0FPvVjEUHwRBXSLAQQEOgG3b8o3CIMc/vlYJJhRD6t6vQvfDnT5pn5TpN7 CCM6suqdTj3mlyhwShzRGsUuzVF7+zzJVCbaKVKDFG1Pglw/8PC/kuEzWACQcCj7QDQ7 NkPuUDdMJlNAyUZefsbALbZ4+Cbk0xtCONOdtNpr9ToDbVbMph1PLZp3tiVxpZ0z9Bhj o52g== X-Gm-Message-State: ALoCoQla9iwAFN2GoCJ9IENSNITahF+reFucK5esu25RxNTLdHqOpXRdX344ozw52lrOLmcJLohLKN0pw78WI6VmzaPXfZNskQ== X-Received: by 10.107.11.68 with SMTP id v65mr37613675ioi.188.1453392018400; Thu, 21 Jan 2016 08:00:18 -0800 (PST) In-Reply-To: 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:101979 On Thu, Jan 21, 2016 at 8:12 AM, Charles T. Smith wrote: >>> would you explain to me why I get this: >>> >>> (PDB)hexdump(msg) >>> *** NameError: name 'hexdump' is not defined >> >> Probably because the name 'hexdump' is not defined. > > > If indeed it's not defined, then I wouldn't think there'd be a > problem importing the module that defines it. What happens if you just do 'import utilities'. Can you then call utilities.hexdump? Can you see anything in the utilities module? > 'hexdump': , > 'int.hexdump': None, > > > But I suspect the first, at any rate, was loaded because of this in > my ~/.pdbrc: > > from hexdump import hexdump > > which wouldn't interfere when running without the debugger (that module > in my sys.path but nowhere near my project) > > > I have this in my project: > > int/__init__.py > > But: > > $ ls int/hexdump* > ls: cannot access int/hexdump*: No such file or directory > > So I don't really understand "int.hexdump". The value of None in sys.modules caches a relative import miss. All it means is that at some point something in the 'int' package tried to do a relative import of the hexdump module and failed (presumably because it doesn't exist). Side observation: 'int' is a bad name for a package, because it will shadow the name of the 'int' built-in.