Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'python,': 0.02; 'win32': 0.03; 'importing': 0.05; 'subject:Python': 0.06; '(using': 0.07; '21,': 0.07; 'modified': 0.07; 'python3': 0.07; 'broke': 0.09; 'friday,': 0.09; 'cc:addr:python-list': 0.11; 'python': 0.11; "'__doc__',": 0.16; "'__file__',": 0.16; '*you*': 0.16; '-tkc': 0.16; 'attention,': 0.16; 'finds': 0.16; 'folder,': 0.16; 'from:addr:python.list': 0.16; 'from:addr:tim.thechases.com': 0.16; 'from:name:tim chase': 0.16; 'imports': 0.16; 'invocation': 0.16; 'script?': 0.16; 'subject: \n ': 0.16; 'subject:dependencies': 0.16; 'subject:import': 0.16; 'sys.path': 0.16; 'modification': 0.16; 'wrote:': 0.18; 'things.': 0.19; 'import': 0.22; 'cc:addr:python.org': 0.22; 'print': 0.22; 'creating': 0.23; 'module,': 0.24; 'cc:2**0': 0.24; 'cc:no real name:2**0': 0.24; "i've": 0.25; 'values': 0.27; 'header:In-Reply- To:1': 0.27; 'thus': 0.29; 'tim': 0.29; 'relative': 0.30; "skip:' 10": 0.31; 'chase': 0.31; 'file': 0.32; 'linux': 0.33; 'subject:the': 0.34; 'johnson': 0.35; 'test': 0.35; 'version': 0.36; 'module.': 0.36; 'charset:us-ascii': 0.36; 'should': 0.36; 'two': 0.37; 'received:10': 0.37; 'needed': 0.38; 'skip:[ 10': 0.38; 'files': 0.38; 'issue': 0.38; 'stock': 0.39; 'skip:p 20': 0.39; 'subject:"': 0.60; 'break': 0.61; "you're": 0.61; 'making': 0.63; 'name': 0.63; 'provide': 0.64; 'different': 0.65; 'to:addr:gmail.com': 0.65; 'received:46': 0.66; 'due': 0.66; 'behaviors': 0.74; 'skip:$ 10': 0.81; 'indirect': 0.84; 'overloading': 0.84; 'subject:history': 0.84; 'watched': 0.91; 'rick': 0.93 X-Sender-Id: wwwh|x-authuser|tim@thechases.com X-Sender-Id: wwwh|x-authuser|tim@thechases.com X-MC-Relay: Neutral X-MailChannels-SenderId: wwwh|x-authuser|tim@thechases.com X-MailChannels-Auth-Id: wwwh X-MC-Loop-Signature: 1416586472328:1620274771 X-MC-Ingress-Time: 1416586472328 Date: Fri, 21 Nov 2014 10:12:55 -0600 From: Tim Chase To: Rick Johnson Subject: Re: PyWart: "Python's import statement and the history of external dependencies" In-Reply-To: <2886a22f-54f6-4d54-b064-911fc0f03ed2@googlegroups.com> References: <066c46c8-a04d-4489-b15a-b603c1b1818b@googlegroups.com> <8661e407-4472-4208-97c2-f666f6502c67@googlegroups.com> <2886a22f-54f6-4d54-b064-911fc0f03ed2@googlegroups.com> X-Mailer: Claws Mail 3.8.1 (GTK+ 2.24.10; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-AuthUser: tim@thechases.com Cc: python-list@python.org X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 50 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1416587630 news.xs4all.nl 2937 [2001:888:2000:d::a6]:55961 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:81223 On 2014-11-21 07:52, Rick Johnson wrote: > On Friday, November 21, 2014 4:29:48 AM UTC-6, Tim Chase wrote: > > > What messed-up version of Python are you running? > > Or did you fail to test your conjecture? > > > > $ cat > calendar.py > > print("This is my local calendar.py") > > x=1 > > $ cat > importtest.py > > import calendar > > print(dir(calendar)) > > $ python2 importtest.py > > This is my local calendar.py > > ['__builtins__', '__doc__', '__file__', '__name__', > > '__package__', 'x'] $ python3 importtest.py > > This is my local calendar.py > > ['__builtins__', '__cached__', '__doc__', '__file__', '__name__', > > '__package__', 'x'] > > > > It finds my local module, not the system "calendar" module. > > You failed to provide the needed information! > > 1. We need to see the values in sys.path. So print them > directly before making the call to import. > > 2. Where did you store your custom "calendar.py" script? Had you paid attention, having watched the creation of the two files and the invocation of stock python, you would know that they were in the same folder, and there's no modification of sys.path in the process. So if you're seeing different behaviors due to a modified sys.path, then you should be aware that *you* modified sys.path and thus broke things. The above was tested on Python2 and Python3, both on Linux (Debian in this case) and Win32 (using "copy con" instead of "cat >") with the out-of-box install. The only time I've been stung by name overloading is in the indirect case of creating a local email.py file and then importing smtplib only to have things break in unforeseen ways. If smtplib used relative imports for $STDLIB/email.py I suspect it would ameliorate that particular issue for me. -tkc