473,385 Members | 1,769 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

How do I refer to a data file relative to a package or installation directory?

I have a package that includes some data files. I am planning to use a
distutils setup script to install the package. How can I compute a path
name for such a data file that will always be relative to my package
root directory (i.e. both when installed, and in my development directory?)

Or to rephrase, say the data file is mypkg/data/foo.dat relative to the
package root "mypkg" (the directory that holds __init__.py). Is there an
enquiry that will return the absolute path prefix for mypkg?
-- Parzival
-- Reply-to is confuggled: parzp (@) shaw (.) ca

Jul 18 '05 #1
1 1538
Parzival wrote:
I have a package that includes some data files. I am planning to use a
distutils setup script to install the package. How can I compute a path
name for such a data file that will always be relative to my package
root directory (i.e. both when installed, and in my development directory?)

Or to rephrase, say the data file is mypkg/data/foo.dat relative to the
package root "mypkg" (the directory that holds __init__.py). Is there an
enquiry that will return the absolute path prefix for mypkg?


Presumably you meant that relative to the package root "mypkg",
the data file is actually at "data/foo.dat", or as some might
write it "./data/foo.dat"? If not, you've got an extra layer
there confusing things.

Basically, just use __file__ inside the __init__.py module to find
that file's location, then use os.path.split() to pull off the
path part and os.path.join() to add the "data/foo.dat" part.

If that's not enough, please post some kind of code snippet
to help explain things better.

-Peter
Jul 18 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Alexander Kienzle | last post by:
I'm new to Java programming. I'm developing a Servlet for tomcat which needs an external configuration file. With external I mean a file (in XML format) which is customizable and not contained in...
7
by: Richard Shea | last post by:
Hi - I'd like to try applying internationalisation techniques to get an idea of how much extra work is involved. As a first step I'm looking at the class based gettext. I just wondered if anyone...
10
by: Edlueze | last post by:
I am developing some Data Access Pages (DAP) using Microsoft Access 2003 on Microsoft Windows XP. When I try to open these pages (located on my C: drive), the display of the data access page is...
6
by: Nadav | last post by:
Hi, I am writing some kind of a file scanner, at certain time all of the files under a certain directory will be scanned, this scan require de-compression of common files formats such as ZIP and...
6
by: Darhl Thomason | last post by:
I thought I was creating a simple little app, but it's kicking my butt right now. I've searched the help and can't find enough to get me where I need to be. I'm creating a CD to distribute to...
2
by: Bill | last post by:
I have an Access 2003 database application that I split into an application component MDB file (i.e., forms, etc) and a data component MDB file (i.e., tables, etc.). I used the 2003 developer...
9
by: KarlM | last post by:
After reading some articles regarding confuguration data I'm a bit confused. Where is the right place for storing configuration data? - XML-files? - registry? - INI-files? (from a users point...
0
by: Alan Isaac | last post by:
What is the recommended packaging of demo scripts or test scripts for a package that has modules that use relative imports? Example: Suppose I have the package structure: package/...
0
Debadatta Mishra
by: Debadatta Mishra | last post by:
Introduction In this article I will provide you an approach to manipulate an image file. This article gives you an insight into some tricks in java so that you can conceal sensitive information...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.