<div dir="ltr"><div>Yep. I followed from bltmodule.c(the import function) and got to the import.c file, and finally got lost.<br><br><br></div>Regards.<br></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Jul 21, 2015 at 12:16 PM, Mark Lawrence <span dir="ltr"><<a href="mailto:breamoreboy@yahoo.co.uk" target="_blank">breamoreboy@yahoo.co.uk</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="HOEnZb"><div class="h5">On 21/07/2015 16:35, Shiyao Ma wrote:<br>
</div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div class="h5">
Hi,<br>
<br>
It looks to me that the import system of Python will ignore invalid<br>
directories and cache the result in memory.<br>
<br>
For example, the following code:<br>
paste here: <a href="https://bpaste.net/show/b144deb42620" rel="noreferrer" target="_blank">https://bpaste.net/show/b144deb42620</a><br>
<br>
#!/usr/bin/env python3<br>
<br>
import sys<br>
import os<br>
import shutil<br>
<br>
sys.path.append("./test")<br>
shutil.rmtree("./test", ignore_errors=True)<br>
<br>
try:<br>
import foo<br>
except ImportError:<br>
os.mkdir("./test")<br>
with open("./test/foo.py", "w") as f:<br>
f.write("print(3)")<br>
<br>
import foo<br>
<br>
the second import foo will fail even though it's there. This is because<br>
when doing the first import foo, the directory .test doesn't exist, and<br>
Python ignores that directory forever.<br>
<br>
<br>
I am interested in the c side implementation of this "ignoring" part.<br>
<br>
<br>
Any body help me to pinpoint the exact c source location?<br>
<br>
Thanks.<br>
<br>
--<br>
<br></div></div>
吾輩は猫である。ホームーページは<a href="https://introo.me" rel="noreferrer" target="_blank">https://introo.me</a> <<a href="http://introo.me" rel="noreferrer" target="_blank">http://introo.me</a>>。<br>
<br>
</blockquote>
<br>
Start here <a href="https://hg.python.org/cpython/file/6629773fef63/Python/import.c" rel="noreferrer" target="_blank">https://hg.python.org/cpython/file/6629773fef63/Python/import.c</a><span class="HOEnZb"><font color="#888888"><br>
<br>
-- <br>
My fellow Pythonistas, ask not what our language can do for you, ask<br>
what you can do for our language.<br>
<br>
Mark Lawrence<br>
<br>
-- <br>
<a href="https://mail.python.org/mailman/listinfo/python-list" rel="noreferrer" target="_blank">https://mail.python.org/mailman/listinfo/python-list</a><br>
</font></span></blockquote></div><br><br clear="all"><br>-- <br><div class="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div><br></div><div>吾輩は猫である。ホームーページは<a href="http://introo.me" target="_blank">https://introo.me</a>。<br></div></div></div></div></div>
</div>