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)
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
> 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(ConfigParser)
-Larry Bates
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.ConfigParser()
config.read(filename)
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
Sorry, the question seems to have completely gone out of my head ...
regards
Steeve
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC/Ltd http://www.holdenweb.com
Skype: holdenweb http://holdenweb.blogspot.com
Recent Ramblings http://del.icio.us/steve.holden
example:
myprog -i C:\aaa\bbb\myprog.ini
As a default I do config.read('myprog.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