<br><br><div class="gmail_quote">---------- Forwarded message ---------<br>From: Wiktor Matuszewski <<a href="mailto:pywkm@wukaem.pl">pywkm@wukaem.pl</a>><br>Date: Tue Nov 11 2014 at 4:47:10 AM<br>Subject: Re: [Tutor] Project tree<br>To: Danny Yoo <<a href="mailto:dyoo@hashcollision.org">dyoo@hashcollision.org</a>><br><br><br>W dniu 2014-11-11 o 03:02, Danny Yoo pisze:<br>
<br>
> See: <a href="https://docs.python.org/3/tutorial/modules.html#intra-package-references" target="_blank">https://docs.python.org/3/<u></u>tutorial/modules.html#intra-<u></u>package-references</a><br>
> for more details.<br>
><br>
> If you have more questions, please feel free to ask!<br>
<br>
Hi Danny, thanks.<br>
I've seen this part of tutorial earlier, but obviously I misunderstood<br>
it. This part especially: "Note that relative imports are based on the<br>
name of the current module".<br>
<br>
When I execute moda.py separately - there's no problem with importing<br>
modb relatively from it. And I thought, that during importing moda from<br>
start.py, for short moment I'm "locally" in moda (that this is current<br>
module) and every import statements in it works relatively to moda.py<br>
not to start.py.<br>
<br>
Can you please explain what is happening step by step when I'm executing<br>
only moda.py, and what is happening when I'm executing start.py? And<br>
what is different when it's executed in Py2?<br>
Or even better, maybe you can write short snippet of code, which I could<br>
paste to all three files, and it will print out all this differences<br>
during execution (you know - so I could be able to track current_module,<br>
path_where_i_am, and path_of_relative_import). I tried to put<br>
"print(__name__)" and "print(os.getcwd())" in every file in this tree,<br>
but it's not quite that. Output looks the same in Py2 and Py3, so it<br>
gives me no explanation.<br>
<br>
<br>
Is there a simple way of importing modb from moda (in Py3), that will<br>
work when moda.py is executed directly (you know - for unit testing),<br>
but also when start.py is executed (for testing whole "package"). For<br>
now I use this try/except block:<br>
<br>
try:<br>
     import modb<br>
except ImportError:<br>
     from . import modb<br>
<br>
But I'm not sure if it's Pythonic, and if there's no simpler solution.<br>
<br>
--<br>
Best regards,<br>
Wiktor Matuszewski<br>
</div>