Stefan H. Holek wrote:
> I don't think there is any way whatsoever in Zope 3. There is no
> "instance" home to begin with, and the os.pardir hacks don't work
> either because you can't really know where your package is installed.
> On 6. Nov 2007, at 11:02, Eric Br�hault wrote:
>> I had a look to different source code, and apparently the solution is
>> to use
>> the path of the current file to get the instance home, so we have
>> code like
>> os.pardir, os.pardir, os.pardir, os.pardir))
>> Is there any easier (and cleaner) way to do it ?
I have found useful another trick related to __file__ .
If the file system location you are looking for is near code you are
using or can import, python's "inspect" may be your friend.
>>> import inspect
So, if your object is, for example, a view method and you need the
directory where another method is defined for your view, you can
>>> sourcefilepath = inspect.getsourcefile(self.otherMethod)
Here's another example for clarification. It works, but is not
Let's say we want to know the file system location where
Decimal.normalize is defined.
>>> from inspect import getsourcefile
>>> from decimal import Decimal
We can get the location directly:
Or, if we just want the location of the class:
or, we can get the location from an instance:
>>> d = Decimal('0.12')
>From there, standard os.path functions can get you locations relative to
the location given.
Zope3-users mailing list