<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <meta content="text/html; charset=ISO-8859-1"
 http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
On 11/30/2010 12:58 AM, Karim wrote:
<blockquote cite="mid:4CF43E1A.5060207@free.fr" type="cite">
  <meta content="text/html; charset=ISO-8859-1"
 http-equiv="Content-Type">
On 11/29/2010 09:15 PM, Karim wrote:
  <blockquote cite="mid:4CF409F8.6010704@free.fr" type="cite">
    <meta http-equiv="content-type"
 content="text/html; charset=ISO-8859-1">
    <br>
Hello every one,<br>
    <br>
I created a package with the following structure:<br>
    <br>
    <ul>
      <li>ops/</li>
      <ul>
        <li>__init__.py</li>
        <li>tcl/</li>
        <ul>
          <li>__init__.py</li>
          <li>pythontcl.py</li>
        </ul>
      </ul>
    </ul>
    <br>
    <br>
&gt; <b>python -c "import sys; print sys.path; import
ops.tcl.pythontcl"</b><br>
    <br>
['',
'/usr/local/lib/python2.6/dist-packages/pyparsing-1.5.5-py2.6.egg', '<b>/home/karim/build/UML2PDK/lib/python</b>',
'/usr/lib/python2.6',
'/usr/lib/python2.6/plat-linux2',
'/usr/lib/python2.6/lib-tk',
'/usr/lib/python2.6/lib-old',
'/usr/lib/python2.6/lib-dynload', '/usr/lib/python2.6/dist-packages',
'/usr/lib/python2.6/dist-packages/PIL',
'/usr/lib/python2.6/dist-packages/gst-0.10',
'/usr/lib/pymodules/python2.6',
'/usr/lib/python2.6/dist-packages/gtk-2.0',
'/usr/lib/pymodules/python2.6/gtk-2.0',
'/usr/lib/python2.6/dist-packages/wx-2.8-gtk2-unicode',
'/usr/local/lib/python2.6/dist-packages']<br>
    <font color="#ffcc00">/</font><b><font color="#ffcc00">home/karim/build/UML2PDK/lib/python/ops/tcl/pythontcl.py:109:
RuntimeWarning:
Parent
module 'pythontcl' not found while handling
absolute import<br>
&nbsp; import unittest<br>
/home/karim/build/UML2PDK/lib/python/ops/tcl/pythontcl.py:110:
RuntimeWarning: Parent module 'pythontcl' not found while handling
absolute import<br>
&nbsp; import sys</font></b><br>
    <br>
At the lines I import standard modules sys and unittest I get these
non-sense warning (my consideration) though I added the top package
root, namely, <b>/home/karim/build/UML2PDK/lib/python. The
programesecute correctly but I alaways get this nerving warning.<br>
    <br>
    </b>Any idea will be welcome!<b><span class="moz-smiley-s1"><span>
:-) </span></span><br>
    <br>
    </b>Regards<br>
Karim<b><br>
    </b></blockquote>
  <br>
I believed I know why:<br>
  <br>
  <font color="#ff0000">Traceback (most recent call last):<br>
&nbsp; File "&lt;string&gt;", line 1, in &lt;module&gt;<br>
&nbsp; File "/home/karim/build/UML2PDK/lib/python/ops/tcl/pythontcl.py",
line 119, in &lt;module&gt;<br>
&nbsp;&nbsp;&nbsp; print sys.modules[__package__]<br>
KeyError: 'pythontcl'</font><br>
  <br>
It is due to method determine parent in class ModuleImporter.<br>
I don't know why sys.modules has the key 'ops.tcl.pythontcl'<br>
and this class search for the key module 'pythontcl'.<br>
  <br>
Big mess between relative path or whatever.<br>
  <br>
Any idea to fix that?<br>
  <br>
Karim<br>
  <br>
</blockquote>
<br>
Ok fixed.<br>
I must not set the special variable __name__. I set it for pydoc
docstrings.<br>
Now the __name__ is automatically set to 'ops.tcl.pythontcl' and
__package__ is set correctly to 'ops.tcl'.<br>
<br>
Kind Regards<br>
Karim<br>
</body>
</html>