The filename and its path is in global variable __file__ (that is
different in any source file)

try

import os.path

file=open(os.path.join(os.path.dirname(__file__), 'hauteur.yaml'))




On 30 mai, 22:22, EuGeNe Van den Bulke <[EMAIL PROTECTED]>
wrote:
> Hi there,
>
> I have a "problem" which could be a bad design on my behalf but I am not
> sure so ...
>
> I have a package WMI which contains a module hauteur.py which, when
> imported, load data from a file located in WMI/data/. In hauteur.py I
> call open('data/hauteur.yaml').
>
> test.py
> WMI/
>      hauteur.py
>      data/
>          hauteur.yaml
>      lot.py
>
> It works well when hauteur is imported in lot.py but if I try import
> WMI.hauteur in test.py it doesn't work because it looks for the
> hauteur.yaml file in the "wrong" place.
>
> Is there a way to tell a module in a package to look for a file in a
> specific place i.e. a within package location?
>
> Thanks,
>
> EuGeNe --http://www.3kwa.com


-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to