My Python application includes some data files that need to be accessed by
modules I distribute with it.
Where can I put them, and how should I arrange my code, so that it works
across platforms?
On Linux, I could install the data to "/usr/lib/myprogram/datafile", and
on Windows to "datafile" relative to where the executable (made by
py2exe) is installed. Then I could detect the operating system, and choose
appropriately.
To be that explicit seems undesirable. Any cleverer ideas?
Tom
(Please CC me on replies: I'm not subscribed. The From address is munged) 6 1662
Tom E H wrote:
My Python application includes some data files that need to be accessed by
modules I distribute with it.
Where can I put them, and how should I arrange my code, so that it works
across platforms?
On Linux, I could install the data to "/usr/lib/myprogram/datafile", and
on Windows to "datafile" relative to where the executable (made by
py2exe) is installed. Then I could detect the operating system, and choose
appropriately.
To be that explicit seems undesirable. Any cleverer ideas?
Tom
(Please CC me on replies: I'm not subscribed. The From address is munged)
I almost always send along an application.ini file and put the location
of where my data is to be stored in that file instead of imbedding (or
worse, hard-coding) it in the application program itself. I also put
other parameters that the user might want to change that will change
the behavior of my program (debugging, logging, etc.) there also. Then
during installation I modify the option in this file with the install
script.
Something like:
[init]
debug=0
quiet=0
datafilepath=/usr/lib/myprogram/datafile
or
[init]
debug=0
quiet=0
datafilepath=C: \Program Files\myprogram \datafile
Then I use ConfigParser in my application to read this file and
extract the parameters. Makes it easy for more experienced users
(and me) to be able to easily relocate the datafile if they
desire.
On Windows I use Inno Installer and it can modify these options inside the
..ini file during the installation so that datafilepath points to where
my data actually will live. Works perfectly for me.
-Larry Bates
Tom E H wrote:
My Python application includes some data files that need to be accessed by
modules I distribute with it.
Where can I put them, and how should I arrange my code, so that it works
across platforms?
On Linux, I could install the data to "/usr/lib/myprogram/datafile", and
on Windows to "datafile" relative to where the executable (made by
py2exe) is installed. Then I could detect the operating system, and choose
appropriately.
To be that explicit seems undesirable. Any cleverer ideas?
Tom
(Please CC me on replies: I'm not subscribed. The From address is munged)
I almost always send along an application.ini file and put the location
of where my data is to be stored in that file instead of imbedding (or
worse, hard-coding) it in the application program itself. I also put
other parameters that the user might want to change that will change
the behavior of my program (debugging, logging, etc.) there also. Then
during installation I modify the option in this file with the install
script.
Something like:
[init]
debug=0
quiet=0
datafilepath=/usr/lib/myprogram/datafile
or
[init]
debug=0
quiet=0
datafilepath=C: \Program Files\myprogram \datafile
Then I use ConfigParser in my application to read this file and
extract the parameters. Makes it easy for more experienced users
(and me) to be able to easily relocate the datafile if they
desire.
On Windows I use Inno Installer and it can modify these options inside the
..ini file during the installation so that datafilepath points to where
my data actually will live. Works perfectly for me.
-Larry Bates
Larry Bates wrote:
Tom E H wrote:
>My Python application includes some data files that need to be accessed by modules I distribute with it.
Where can I put them, and how should I arrange my code, so that it works across platforms?
I almost always send along an application.ini file and put the location
of where my data is to be stored in that file instead of imbedding (or
worse, hard-coding) it in the application program itself.
Something like:
[init]
debug=0
quiet=0
datafilepath=/usr/lib/myprogram/datafile
Well that's great, but how do you access the ini file portably?
Tom
Tom E H wrote:
Larry Bates wrote:
>Tom E H wrote:
>>My Python application includes some data files that need to be accessed by modules I distribute with it.
Where can I put them, and how should I arrange my code, so that it works across platforms?
I almost always send along an application.ini file and put the location of where my data is to be stored in that file instead of imbedding (or worse, hard-coding) it in the application program itself.
>Something like:
[init] debug=0 quiet=0 datafilepath =/usr/lib/myprogram/datafile
Well that's great, but how do you access the ini file portably?
Tom
From my original post:
Then I use ConfigParser in my application...
for help on ConfigParser you can do:
import ConfigParser
help(ConfigPars er)
-Larry Bates
Larry Bates wrote:
>Well that's great, but how do you access the ini file portably?
From my original post:
Then I use ConfigParser in my application...
Thanks, but where in the directory structure do you put the ini file on
different platforms? Presumably you have to hard-code that into the source
and then do operating system type detection?
i.e. if I make my config parser:
import ConfigParser
config = ConfigParser.Co nfigParser()
config.read(fil ename)
What do you use for filename on Windows? What on Linux? OSX? etc. How do
you detect which operating system you are running on?
Tom
Tom E H wrote:
Larry Bates wrote:
>>Well that's great, but how do you access the ini file portably?
From my original post:
Then I use ConfigParser in my application...
Thanks, but where in the directory structure do you put the ini file on
different platforms? Presumably you have to hard-code that into the source
and then do operating system type detection?
i.e. if I make my config parser:
import ConfigParser
config = ConfigParser.Co nfigParser()
config.read(fil ename)
What do you use for filename on Windows? What on Linux? OSX? etc. How do
you detect which operating system you are running on?
Tom
I almost always have the .ini configuration file live in the same
directory/folder as the program or sometimes in a subdirectory of
the install directory (which I reference relative to where the
program is run from). Typically I install a default .ini file
via program installer (I like Inno Installer on Windows). I also
make all my programs accept a -i <configuratio n file pathargument
when they are run so you can override the default .ini file on the
command line.
example:
myprog -i C:\aaa\bbb\mypr og.ini
As a default I do config.read('my prog.ini') it always reads from
the current directory (which is where the program is installed).
To access a subdirectory of the current directory I do something
like:
p=os.path.join( os.getcwd(), 'configfiles')
config.read(p)
I haven't put anything on OSX but this works fine on Windows
and Linux and should work on OSX.
-Larry Bates This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Suzanne Vogel |
last post by:
Hi,
Given: I have a class with protected or private data members, some of
them without accessor methods. It's someone else's class, so I can't
change it. (eg, I can't add accessor methods to the parent class, and I
can't make some "helper" class a friend of the parent class to help in
accessing the data.)
Problem: I want to derive a class that has a copy constructor that
properly copies those data members.
|
by: Tom |
last post by:
Let's say I've got a class defined in a header file.
class foo {
private:
...
int bar;
....
};
Now lets say I have a function that needs to access the private variable
|
by: Tony Houghton |
last post by:
I'm using pygame to write a game called Bombz which needs to save some
data in a directory associated with it. In Unix/Linux I'd probably use
"~/.bombz", in Windows something like
"C:\Documents And Settings\<user>\Applicacation Data\Bombz".
There are plenty of messages in the archives for this group about how to
find the correct location in Windows, but what about Mac OS? There I
don't know the correct location for this sort of thing at...
|
by: prodirect |
last post by:
Hi all,
I hope someone can help me. I've recently created a database and wanted to
put it up on an ftp sight so that multiple people could access the same
tables at the same time from different geographical locations. I have been
completely unsucessful in acheiving this goal so far however.
Things I have tried:
Create a shortcut to ftp sight via browser then tried to map local drive to
|
by: Eugen Walcher |
last post by:
Hello all, I've tried posting this same question on other newsgroups
with no luck. This group seems to have a lot more activity so I
apologize if you have seen it before.
I'm trying to create a web service in c# using paradox data. The data
is stored locally on my development machine with IIS also installed.
Web services are working to the point where I can return strings and
ints using Access2000 data but whenever I try and...
| |
by: nkrisraj |
last post by:
Hi,
I have a following structure:
typedef struct
{
RateData rdr;
int RateID;
char RateBalance;
} RateInfo;
|
by: rsood |
last post by:
Hi
I'm developing a program, and naturally I want it to be as portable as
possible. I need to be able to access specific numbers of bytes in it,
but as far as I know, there is no keyword in the c language such as
'byte'. Is it always okay to assume that the char data type is always
1 byte, or is there some other way to be sure you are getting 1 byte
that is not processor/OS dependent that is better, or is there no way
to be both...
|
by: Kavya |
last post by:
Here is the code
int main(){
struct node{
int a;
int b;
int c;
};
struct node s={3,5,6};
struct node *ptr=&s;
|
by: Noy B |
last post by:
Hi,
I have developed a small application that is using a MSAccess DB.
the problem is that it was developed on a machine where the
application and the DB are both located.
now it needs to be change that the application will be able to run on
any other machine (using \\ syntax on the run command- not a problem)
using the DB located on a static-different machine.
for this purpose I need to create a Remote Connection from my
|
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,...
|
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...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |