[Chicago] import question

Kumar McMillan kumar.mcmillan at gmail.com
Tue Jan 22 23:37:15 CET 2008


On Jan 22, 2008 3:59 PM, Massimo Di Pierro <mdipierro at cs.depaul.edu> wrote:
> Hello everybody,
>
> I was hoping you could help me.
>
> Say I have a module called test
>
> test/
>     __init__.py
>     other.py
>
> and __init__.py says
>
>     from test.other import something
>
> so that I can
>
>     from test import something
>
> Now I do not want to install the module but I want to place it under
> a folder called contrib:
>
> contrib/
>     test/
>        __init__.py
>        other.py
>
> and I want to be able to say
>
>    from contrib.test import something

that statement would not be possible without adding
contrib/__init__.py (I don't see that in your dir structure).  Maybe
that's all you need?


separate but related: you probably want to avoid naming top level
modules the same as stdlib modules.  "test" believe it or not is a
stdlib module.  It should really be called "test_python" because
that's what it does but that will never change.  I've taken to naming
my free-standing test module "tests" and I've noticed most other
packages do this too.  However, I usually prefer to make test a
submodule.  That is, myapp.test

K

>
> Now __init__ fails to find test.other because that's contrib.test.other.
>
> Two natural solutions are:
> 1) edit __init__.py and replace test.other with write
> contrib.test.other. This is not acceptable for me since I do not want
> to maintain the test module.
> 2) add contrib to the path. This is also not acceptable because
> creates countless problems with py2exe and py2app. I have many
> modules and files with similar issues.
>
> Does anybody know of a third solution?
>
> Massimo
>
> P.S. No need to say this has something to do with www.web2py.com
> _______________________________________________
> Chicago mailing list
> Chicago at python.org
> http://mail.python.org/mailman/listinfo/chicago
>


More information about the Chicago mailing list