[Zope] External Method importing modules

2007-02-13 Thread Alan

Dear List,

I have an external method and now I developed I new module in a
separated file and then I am trying to make my external method to
import it but I am failing here. Where should place my module file in
order to be found by my external method?
I tried to place it in the same folder of my external method, but no success.

Any help would be very appreciated. Many thanks in advance.

Cheers,
Alan

--
Alan Wilter S. da Silva, D.Sc. - CCPN Research Associate
Department of Biochemistry, University of Cambridge.
80 Tennis Court Road, Cambridge CB2 1GA, UK.

http://www.bio.cam.ac.uk/~awd28

___
Zope maillist  -  Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
http://mail.zope.org/mailman/listinfo/zope-announce

http://mail.zope.org/mailman/listinfo/zope-dev )


Re: [Zope] External Method importing modules

2007-02-13 Thread Andreas Jung



--On 13. Februar 2007 12:53:25 + Alan [EMAIL PROTECTED] wrote:


Dear List,

I have an external method and now I developed I new module in a
separated file and then I am trying to make my external method to
import it but I am failing here. Where should place my module file in
order to be found by my external method?
I tried to place it in the same folder of my external method, but no
success.


Since the module must be importable, it must be available in some location
as defined through sys.path or $PYTHONPATH. Check the Python docs for 
additional info on that topic.


-aj

pgpQcuB0jgR9M.pgp
Description: PGP signature
___
Zope maillist  -  Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope-dev )


Re: [Zope] External Method importing modules

2007-02-13 Thread Alan

Thanks Andreas, I am trying with:

if sys.path.count(myPath) == 0: sys.path.insert(0, myPath)

where myPath should be '[Zope installation folder]/instance/import'.
So my question now is: is there a variable inside Zope which can
returns the 'import' path?

Many thanks in advance.

Cheers,
Alan

On 13/02/07, Andreas Jung [EMAIL PROTECTED] wrote:



--On 13. Februar 2007 12:53:25 + Alan [EMAIL PROTECTED] wrote:

 Dear List,

 I have an external method and now I developed I new module in a
 separated file and then I am trying to make my external method to
 import it but I am failing here. Where should place my module file in
 order to be found by my external method?
 I tried to place it in the same folder of my external method, but no
 success.

Since the module must be importable, it must be available in some location
as defined through sys.path or $PYTHONPATH. Check the Python docs for
additional info on that topic.

-aj




--
Alan Wilter S. da Silva, D.Sc. - CCPN Research Associate
Department of Biochemistry, University of Cambridge.
80 Tennis Court Road, Cambridge CB2 1GA, UK.

http://www.bio.cam.ac.uk/~awd28

___
Zope maillist  -  Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
http://mail.zope.org/mailman/listinfo/zope-announce

http://mail.zope.org/mailman/listinfo/zope-dev )


Re: [Zope] External Method importing modules

2007-02-13 Thread Andreas Jung



--On 13. Februar 2007 13:10:17 + Alan [EMAIL PROTECTED] wrote:


Thanks Andreas, I am trying with:

if sys.path.count(myPath) == 0: sys.path.insert(0, myPath)


What's the sense of this code? sys.path is usually *never* empty.
You should really look at the Python docs and learn where Python is looking 
by default for modules. Is is perfectly documented - python.org - 
documentation.


In addition you would like to check for the existence of an item in 
sys.path using


if myPath in sys.path:



-aj

pgp96jJNlbS0E.pgp
Description: PGP signature
___
Zope maillist  -  Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope-dev )


Re: [Zope] External Method importing modules

2007-02-13 Thread Jonathan


- Original Message - 
From: Alan [EMAIL PROTECTED]

To: Andreas Jung [EMAIL PROTECTED]
Cc: zope@zope.org
Sent: Tuesday, February 13, 2007 8:10 AM
Subject: Re: [Zope] External Method importing modules



Thanks Andreas, I am trying with:

if sys.path.count(myPath) == 0: sys.path.insert(0, myPath)

where myPath should be '[Zope installation folder]/instance/import'.
So my question now is: is there a variable inside Zope which can
returns the 'import' path?


You can easily check what's in your sys.path by having your external method 
return it.


Typically, the Extensions directory (where your external methods live) are 
not in the default path and need to be added to sys.path.(warning: be 
careful on how you do this or everytime your external method gets called it 
will add to the sys.path and will eventually cause you grief!).



Jonathan 


___
Zope maillist  -  Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
http://mail.zope.org/mailman/listinfo/zope-announce

http://mail.zope.org/mailman/listinfo/zope-dev )


Re: [Zope] External Method importing modules

2007-02-13 Thread Alan

Well, I did it:

from App.config import getConfiguration
extPath = getConfiguration().instancehome+'/Extensions'
if sys.path.count(extPath) == 0: sys.path.insert(0, extPath)

And it worked for what I wanted.

On 13/02/07, Alan [EMAIL PROTECTED] wrote:

On 13/02/07, Andreas Jung [EMAIL PROTECTED] wrote:
 What's the sense of this code? sys.path is usually *never* empty.
 You should really look at the Python docs and learn where Python is looking
 by default for modules. Is is perfectly documented - python.org -
 documentation.

 In addition you would like to check for the existence of an item in
 sys.path using

  if myPath in sys.path:

Dear Andreas and Jonathan, first a mistake: I want to access
'Extensions' folder as you mentioned Jonathan, not 'import'.

Andreas, I've done that, I can see several path there like
.../instance/Products/Sprout/src, .../lib/python/Zope2/Startup etc.,
but none for .../instance/Extensions.

I was hoping that I could get the path where 'Extensions' is because I
work with several zope installations in several platforms and I would
like to make my module independent of a variable inside its code that
should be manually adjusted for every situation.

And yes, I am aware about adding the path only once (that's why
there's a 'if') and then I avoid recursive insertions.

Cheers,
Alan

--
Alan Wilter S. da Silva, D.Sc. - CCPN Research Associate
Department of Biochemistry, University of Cambridge.
80 Tennis Court Road, Cambridge CB2 1GA, UK.
http://www.bio.cam.ac.uk/~awd28




--
Alan Wilter S. da Silva, D.Sc. - CCPN Research Associate
Department of Biochemistry, University of Cambridge.
80 Tennis Court Road, Cambridge CB2 1GA, UK.

http://www.bio.cam.ac.uk/~awd28

___
Zope maillist  -  Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
http://mail.zope.org/mailman/listinfo/zope-announce

http://mail.zope.org/mailman/listinfo/zope-dev )


Re: [Zope] External Method importing modules

2007-02-13 Thread Dieter Maurer
Alan wrote at 2007-2-13 13:10 +:
if sys.path.count(myPath) == 0: sys.path.insert(0, myPath)

where myPath should be '[Zope installation folder]/instance/import'.
So my question now is: is there a variable inside Zope which can
returns the 'import' path?

Formerly, the ExternalMethod documentation suggested to
put such modules into SOFTWARE_HOME/Shared/your_company/

Nowadays (since Zope 2.7, I think), INSTANCE_HOME/lib/python
is a better place (with any structure you would like to use).
This folder is put on PYTHONPATH automatically. No need to fiddle
with it (I have already searched hours for problems caused by
runtime sys.path manipulations).



-- 
Dieter
___
Zope maillist  -  Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope-dev )