[Zope] Can I do this in a python products ??

Nicolas Évrard Nicolas Évrard
Mon, 6 May 2002 17:33:37 +0200


* Thomas B. Passin <tpassin@mitretek.org> [10:59 03/05/02] : 

>
>There are several possibilities.  Here are some:
>
>1) Use an environmental variable.  This means you have to remember to set
>the variable before running Zope.

Seems a bit like a quick hack no ??

>2) Put your code into a package (put it into a directory on the python path
>and put an __init__.py file into that directory).     When you import the
>package, you can get the complete path from the package's __file__attribute.
>For example, if you have a package called "altlas":
>
>import atlas,os.path
>PATH=os.path.dirname(atlas.__file__)
>
>3) A variation on 2) is to create a variable in the package's __init__.py
>file:
>
>import os.path
>BASEPATH=os.path.dirname(__file__)
>
>Now when you import the package, the BASEPATH variable is available.  To do
>this, you may need to put your code into subdirectories or subpackages under
>the package.

These two solutions seem cool, i'll try them.
but I've found this function by browsing in the source the
ZopeTutorialProduct :

import App.Common

App.Common.package_home seems to return the home of the package  (duh !!)

>4) You could also try making the path be relative to that of Zope by using
>os.cwd() or sys.argv[0], but that might be less robust.

Humm as you say this is less robust. So I won't even try it.


-- 
Évrard Nicolas
SOLIREM SA - Projet Smartainers
1, rue de l'épervier                              Tel: +32 4 248 08 85
B-4040 Herstal                                    Fax: +32 4 248 05 78