Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #94297

Re: Where is the c source code of the import mechanism that ignores invalid directory?

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!1.eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed7.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <python-python-list@m.gmane.org>
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; 'cache': 0.05; 'from:addr:yahoo.co.uk': 0.05; 'importerror:': 0.05; 'memory.': 0.05; 'python3': 0.05; 'sys': 0.05; 'exist,': 0.07; 'shutil': 0.07; 'subject:code': 0.07; '"w")': 0.09; 'foo,': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'python': 0.10; 'ignore': 0.14; 'subject: \n ': 0.15; 'ignores': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'subject:import': 0.16; 'wrote:': 0.16; 'try:': 0.18; 'thanks.': 0.18; 'language': 0.19; 'lawrence': 0.22; 'second': 0.24; 'import': 0.24; 'header:In-Reply-To:1': 0.24; 'header:User- Agent:1': 0.26; "doesn't": 0.26; 'header:X-Complaints-To:1': 0.26; 'skip:# 10': 0.27; 'looks': 0.29; 'subject:that': 0.29; 'code:': 0.29; 'there.': 0.30; 'language.': 0.32; 'source': 0.33; 'url:python': 0.33; 'foo': 0.33; 'except': 0.34; 'fail': 0.35; 'url:org': 0.36; 'to:addr:python-list': 0.36; 'subject:?': 0.36; 'subject:: ': 0.37; 'received:org': 0.37; 'doing': 0.38; 'skip:o 20': 0.38; 'hi,': 0.38; 'subject:the': 0.39; 'to:addr:python.org': 0.40; 'mark': 0.40; 'body': 0.61; 'side': 0.62; 'here:': 0.63; 'our': 0.64; 'url:me': 0.64; 'here': 0.66; '8bit%:100': 0.70; 'url:c': 0.76; 'location?': 0.84; 'pythonistas,': 0.84; 'skip:\xe5 40': 0.84; 'subject:Where': 0.84; 'subject:source': 0.84; 'url:cpython': 0.84; 'url:show': 0.84; 'forever.': 0.93
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Mark Lawrence <breamoreboy@yahoo.co.uk>
Subject Re: Where is the c source code of the import mechanism that ignores invalid directory?
Date Tue, 21 Jul 2015 17:16:27 +0100
References <CAJQX3DxkOd80rujmRf_eafTkxfq5U1hq5SimSZV=ux3VmV5bzw@mail.gmail.com>
Mime-Version 1.0
Content-Type text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding 8bit
X-Gmane-NNTP-Posting-Host host-78-147-188-8.as13285.net
User-Agent Mozilla/5.0 (Windows NT 6.3; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.1.0
In-Reply-To <CAJQX3DxkOd80rujmRf_eafTkxfq5U1hq5SimSZV=ux3VmV5bzw@mail.gmail.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 <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.819.1437495414.3674.python-list@python.org> (permalink)
Lines 52
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1437495414 news.xs4all.nl 2897 [2001:888:2000:d::a6]:43394
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:94297

Show key headers only | View raw


On 21/07/2015 16:35, Shiyao Ma wrote:
> Hi,
>
> It looks to me that the import system of Python will ignore invalid
> directories and cache the result in memory.
>
> For example, the following code:
> paste here: https://bpaste.net/show/b144deb42620
>
> #!/usr/bin/env python3
>
> import  sys
> import  os
> import  shutil
>
> sys.path.append("./test")
> shutil.rmtree("./test",  ignore_errors=True)
>
> try:
>      import  foo
> except  ImportError:
>      os.mkdir("./test")
>      with  open("./test/foo.py",  "w")  as  f:
>          f.write("print(3)")
>
>      import  foo
>
> the second import foo will fail even though it's there. This is because
> when doing the first import foo, the directory .test doesn't exist, and
> Python ignores that directory forever.
>
>
> I am interested in the c side implementation of this "ignoring" part.
>
>
> Any body help me to pinpoint the exact c source location?
>
> Thanks.
>
> --
>
> 吾輩は猫である。ホームーページはhttps://introo.me <http://introo.me>。
>

Start here https://hg.python.org/cpython/file/6629773fef63/Python/import.c

-- 
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: Where is the c source code of the import mechanism that ignores invalid directory? Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-07-21 17:16 +0100

csiph-web