473,651 Members | 2,518 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1555
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
8673
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 my package. I don't want to hardcode any path and I would like to be independent of the application server (tomcat, websphere,...). Until now, I put the file in my package and open it using obj.getClass.getResourceAsStream but when I put my...
7
2619
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 knew of some ready made .MO files I could use - I don't care what the subject matter is I just want something realistic to work with (I have tried googling but a search string with 'sample' and 'file' pulls up an awful lot of unrelated stuff). ...
10
3153
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 blocked and I receive the following error message in the Information Bar in Microsoft Internet Explorer: "To help protect your security, Internet Explorer has restricted this site from showing certain content. Click here for options."
6
8554
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 MSI, the ZIP file format is well known so there is no problem of decompressing it manually, however, the MSI format is less open… I wonder where can I find the MSI format ‘white papers’? Are those ‘white papers’ are published? How can I...
6
4261
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 my field personnel. The purpose of the app is to copy some files from the CD to an obscure destination directory on the machine. The destination directory can change on the target machine and is identified as IcmPath. (IcmPath is populated...
2
2442
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 extensions Package Wizard program to create an installation package. (Note: I included the Access 2003 runtime because the users of my application don't have Access on their machines). My problem is that when a user runes the installation program,...
9
2275
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 of view, ini-files are more comfortable to read and edit) Where should I store user specific config data? Where should I store machine specific config data?
0
1334
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/ __init__.py subpackage1/
0
10751
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 inside an image, hide your complete image as text ,search for a particular image inside a directory, minimize the size of the image. However this is not a new concept, there is a concept called Steganography which enables to conceal your secret...
0
8349
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8275
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8795
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8460
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
5609
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4281
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2696
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1906
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1585
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.