<html><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">
I will look into your module. Thanks<div><br><div><div>On Jan 22, 2008, at 4:36 PM, Cosmin Stejerean wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite">adding both contrib and test in your example to the path is indeed bad since as far as Python is concerned contrib.test and test refer to two separate modules.<br><br>The __init__.py inside of the test package contains "from test.other import something"? It can simply be<br><br>from other import something<br><br>which would bring something into test. This won't work in more complicated situations like <br><br>test/<br> __init__.py<br> package1/<br>   __init__.py<br>   mod1.py<br> package2/<br>  __init__.py<br>   mod2.py<br><br>If mod2.py from package2 needs to reference something from package1 it had no choice traditionally but to refernece package1 as test.package1 (which causes exactly the problems you describe). This is the reason relative imports were added but it does require patching the library in question. I don't think there is any way around this other than: <br><br>1. put the test under an external directory that is added to the path, not inside another package<br>2. patch the library by either<br>   a) using relative imports (breaks compatibility with 2.4 and possibly 2.5)<br>    b) refactor using a library like py-ioc (<a href="http://code.google.com/p/py-ioc/">http://code.google.com/p/py-ioc/</a>), a library that I wrote to solve similar problems<br><br>- Cosmin<br><br><div class="gmail_quote"> On Jan 22, 2008 3:59 PM, Massimo Di Pierro &lt;<a href="mailto:mdipierro@cs.depaul.edu">mdipierro@cs.depaul.edu</a>&gt; wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"> Hello everybody,<br><br>I was hoping you could help me.<br><br>Say I have a module called test<br><br>test/<br>    __init__.py<br>    other.py<br><br>and __init__.py says<br><br>    from test.other import something<br><br> so that I can<br><br>    from test import something<br><br>Now I do not want to install the module but I want to place it under<br>a folder called contrib:<br><br>contrib/<br>    test/<br>       __init__.py<br>       other.py <br><br>and I want to be able to say<br><br>   from contrib.test import something<br><br>Now __init__ fails to find test.other because that's contrib.test.other.<br><br>Two natural solutions are:<br>1) edit __init__.py and replace test.other with write<br>contrib.test.other. This is not acceptable for me since I do not want<br>to maintain the test module.<br>2) add contrib to the path. This is also not acceptable because<br>creates countless problems with py2exe and py2app. I have many <br>modules and files with similar issues.<br><br>Does anybody know of a third solution?<br><br>Massimo<br><br>P.S. No need to say this has something to do with <a href="http://www.web2py.com" target="_blank">www.web2py.com </a><br>_______________________________________________<br>Chicago mailing list<br><a href="mailto:Chicago@python.org">Chicago@python.org</a><br><a href="http://mail.python.org/mailman/listinfo/chicago" target="_blank">http://mail.python.org/mailman/listinfo/chicago </a><br></blockquote></div><br><br clear="all"><br>-- <br>Cosmin Stejerean<br><a href="http://blog.offbytwo.com">http://blog.offbytwo.com</a><span>&lt;ATT00001.txt&gt;</span></blockquote></div><br></div></body></html>