saving settings

S

SuperHik

Hi,

I was wondering how to make a single .exe file, say some kind od clock,
and be able to save some settings (alarm for example) into the same
file? Basically make code rewrite it self...

thanks!
 
A

aum

Hi,

I was wondering how to make a single .exe file, say some kind od clock,
and be able to save some settings (alarm for example) into the same
file? Basically make code rewrite it self...

thanks!

Yikes!!!

I'd strongly suggest you read the doco for ConfigParser, and load/save
your config file to/from os.path.join(os.path.expanduser("~")).

Another option - save your stuff in the Windows Registry
 
S

SuperHik

aum said:
Yikes!!!

I'd strongly suggest you read the doco for ConfigParser, and load/save
your config file to/from os.path.join(os.path.expanduser("~")).

Another option - save your stuff in the Windows Registry

but if I copy this file on the other computer settings will be lost...
 
D

Diez B. Roggisch

SuperHik said:
but if I copy this file on the other computer settings will be lost...

It _might_ come as a shock to you, but when you install e.g. Word on another
computer, there aren't any documents coming with it. Especially not the
ones you wrote on that other machine.

Seriously: Who is going to copy a executable around? Do you know of any
other program that behaves like that?

Diez
 
S

Serge Orlov

SuperHik said:
but if I copy this file on the other computer settings will be lost...

Put your program in a writable folder and save configuration right into
that folder. Then your can transfer the whole folder. Tip: sys.path[0]
always contains the path to the directory where "__main__" module is
located.
 
S

SuperHik

Diez said:
It _might_ come as a shock to you, but when you install e.g. Word on another
computer, there aren't any documents coming with it. Especially not the
ones you wrote on that other machine.
that doesn't shock me :p
anyway you're talking about instalation while I'm talkig about single
standalone file.
Besides, if it was neccessary I bet MS would make that option (and it
wouldn't be a problem since installation is not done from a sinlge file
but from the CD (should be CD-RW in that case) with lots of files and
directories so they'd create just another directory on the installation
CD, say \All Documents\ )
Seriously: Who is going to copy a executable around?
Obviously I am. :D
Do you know of any
other program that behaves like that?
No, but for most programs I used I never bothered to check where did
they put their settings.
That's just the thing, I'm not a professional programmer so I was
wondering is it possible to do it, and if it is how much trouble would
it be. If nothing I will just make a config file right next to the
executable..
thanks!
 
D

Diez B. Roggisch

that doesn't shock me :p
anyway you're talking about instalation while I'm talkig about single
standalone file.
Besides, if it was neccessary I bet MS would make that option (and it
wouldn't be a problem since installation is not done from a sinlge file
but from the CD (should be CD-RW in that case) with lots of files and
directories so they'd create just another directory on the installation
CD, say \All Documents\ )

But that is a folder then. Go put your config-file & program in a folder,
and copy it.
Obviously I am. :D
Do you know of any
No, but for most programs I used I never bothered to check where did
they put their settings.
That's just the thing, I'm not a professional programmer so I was
wondering is it possible to do it, and if it is how much trouble would
it be. If nothing I will just make a config file right next to the
executable..

Nobody does it that way for a simple reason: lets say you stored some
config-information like an IP-address. Now moving your program somewhere
else makes that a wrong config option - and possibly your program crashes
even before you have the chance to _change_ that config setting. Now you
need either a fresh copy - or just edit/delete the config file. The latter
sounds better to me - and most probably quite a few others programmers.

Diez
 
G

Grant Edwards

It _might_ come as a shock to you, but when you install e.g.
Word on another computer, there aren't any documents coming
with it.

Documents and settings aren't quite the same thing, but it's a
valid point.
Especially not the ones you wrote on that other machine.

Seriously: Who is going to copy a executable around?

I do. I copy putty.exe around all of the time.
Do you know of any other program that behaves like that?

Back in the day, that used to be fairly common under
DOS/Windows. Not that it's still not a really bad idea.
 
A

aum

Hi,

I was wondering how to make a single .exe file, say some kind od clock,
and be able to save some settings (alarm for example) into the same
file? Basically make code rewrite it self...

thanks!

Another option I thought of:
- get the Nullsoft NSIS installer
- write a Python wrapper to NSIS if desired
- within your app, include:
- embedded py2exe
- embedded/wrapped NSIS
- within your app offer a menu option to 'export this
program', which changes data files as needed, then invokes
py2exe and NSIS to create a whole new installer exe

That way, you'd have what you're after - a way to distribute your app,
including its current state, as a single EXE file. Also, it would have the
advantage of this EXE being an installer which sets up start menu
shortcuts.
 
D

Diez B. Roggisch

Grant Edwards wrote:

Documents and settings aren't quite the same thing, but it's a
valid point.


I do. I copy putty.exe around all of the time.

I download it every time, and if I didn't, I'd be pretty annoyed if I'd copy
it to a friends machine containing ALL MY KEYS embedded into it.
Back in the day, that used to be fairly common under
DOS/Windows. Not that it's still not a really bad idea.

Back in the day self-modifying code was the craze too. And _some_ people
even do it in python :)

Diez
 
S

SuperHik

Diez said:
Grant Edwards wrote:



I download it every time, and if I didn't, I'd be pretty annoyed if I'd copy
it to a friends machine containing ALL MY KEYS embedded into it.


Back in the day self-modifying code was the craze too. And _some_ people
even do it in python :) those crazy bastards! ;)

Diez
 
T

Ten

but if I copy this file on the other computer settings will be lost...

A pretty standard behaviour in this context is to have your program create
its own config file if it's absent, say on first run, per user, or if it's
copied to a new machine.

Just do it using whatever defaults are in the python file itself.

Regards,

Ten.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top