Home     |     .Net Programming    |     cSharp Home    |     Sql Server Home    |     Javascript / Client Side Development     |     Ajax Programming

Ruby on Rails Development     |     Perl Programming     |     C Programming Language     |     C++ Programming     |     IT Jobs

Python Programming Language     |     Laptop Suggestions?    |     TCL Scripting     |     Fortran Programming     |     Scheme Programming Language

Cervo Technologies
The Right Source to Outsource

MS Dynamics CRM 3.0

Python Programming Language

file / module / package - import problem

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').


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?


EuGeNe -- http://www.3kwa.com

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


import os.path

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

On 30 mai, 22:22, EuGeNe Van den Bulke <eugene.vandenbu@gmail.com>

aspineux wrote:
> import os.path

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

Thanks that worked ;)
Add to del.icio.us | Digg this | Stumble it | Powered by Megasolutions Inc