saving settings

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • SuperHik

    #1

    saving settings

    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!
  • aum

    #2
    Re: saving settings

    On Mon, 29 May 2006 09:05:36 +0200, SuperHik wrote:
    [color=blue]
    > 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![/color]

    Yikes!!!

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

    Another option - save your stuff in the Windows Registry

    --

    Cheers
    aum


    Comment

    • SuperHik

      #3
      Re: saving settings

      aum wrote:[color=blue]
      > On Mon, 29 May 2006 09:05:36 +0200, SuperHik wrote:
      >[color=green]
      >> 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![/color]
      >
      > Yikes!!!
      >
      > I'd strongly suggest you read the doco for ConfigParser, and load/save
      > your config file to/from os.path.join(os .path.expanduse r("~")).
      >
      > Another option - save your stuff in the Windows Registry
      >[/color]

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

      Comment

      • Diez B. Roggisch

        #4
        Re: saving settings

        SuperHik wrote:
        [color=blue]
        > aum wrote:[color=green]
        >> On Mon, 29 May 2006 09:05:36 +0200, SuperHik wrote:
        >>[color=darkred]
        >>> 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![/color]
        >>
        >> Yikes!!!
        >>
        >> I'd strongly suggest you read the doco for ConfigParser, and load/save
        >> your config file to/from os.path.join(os .path.expanduse r("~")).
        >>
        >> Another option - save your stuff in the Windows Registry
        >>[/color]
        >
        > but if I copy this file on the other computer settings will be lost...[/color]

        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

        Comment

        • Serge Orlov

          #5
          Re: saving settings

          SuperHik wrote:[color=blue]
          > aum wrote:[color=green]
          > > On Mon, 29 May 2006 09:05:36 +0200, SuperHik wrote:
          > >[color=darkred]
          > >> 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![/color]
          > >
          > > Yikes!!!
          > >
          > > I'd strongly suggest you read the doco for ConfigParser, and load/save
          > > your config file to/from os.path.join(os .path.expanduse r("~")).
          > >
          > > Another option - save your stuff in the Windows Registry
          > >[/color]
          >
          > but if I copy this file on the other computer settings will be lost...[/color]

          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.

          Comment

          • SuperHik

            #6
            Re: saving settings

            Diez B. Roggisch wrote:[color=blue]
            > SuperHik wrote:
            >[color=green]
            >> aum wrote:[color=darkred]
            >>> On Mon, 29 May 2006 09:05:36 +0200, SuperHik wrote:
            >>>
            >>>> 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.expanduse r("~")).
            >>>
            >>> Another option - save your stuff in the Windows Registry
            >>>[/color]
            >> but if I copy this file on the other computer settings will be lost...[/color]
            >
            > 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.[/color]
            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\ )[color=blue]
            >
            > Seriously: Who is going to copy a executable around?[/color]
            Obviously I am. :D
            Do you know of any[color=blue]
            > other program that behaves like that?[/color]
            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..[color=blue]
            >
            > Diez[/color]
            thanks!

            Comment

            • Diez B. Roggisch

              #7
              Re: saving settings

              > that doesn't shock me :p[color=blue]
              > 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\ )[/color]

              But that is a folder then. Go put your config-file & program in a folder,
              and copy it.
              [color=blue][color=green]
              >>
              >> Seriously: Who is going to copy a executable around?[/color]
              > Obviously I am. :D
              > Do you know of any[color=green]
              >> other program that behaves like that?[/color]
              > 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..[/color]

              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

              Comment

              • Grant Edwards

                #8
                Re: saving settings

                On 2006-05-29, Diez B. Roggisch <deets@nospam.w eb.de> wrote:
                [color=blue]
                > 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.[/color]

                Documents and settings aren't quite the same thing, but it's a
                valid point.
                [color=blue]
                > Especially not the ones you wrote on that other machine.
                >
                > Seriously: Who is going to copy a executable around?[/color]

                I do. I copy putty.exe around all of the time.
                [color=blue]
                > Do you know of any other program that behaves like that?[/color]

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

                --
                Grant Edwards grante Yow! I'm wet! I'm wild!
                at
                visi.com

                Comment

                • aum

                  #9
                  Another option - Re: saving settings

                  On Mon, 29 May 2006 09:05:36 +0200, SuperHik wrote:
                  [color=blue]
                  > 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![/color]

                  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.

                  --

                  Cheers
                  aum


                  Comment

                  • Diez B. Roggisch

                    #10
                    Re: saving settings

                    Grant Edwards wrote:

                    [color=blue]
                    > Documents and settings aren't quite the same thing, but it's a
                    > valid point.
                    >[color=green]
                    >> Especially not the ones you wrote on that other machine.
                    >>
                    >> Seriously: Who is going to copy a executable around?[/color]
                    >
                    > I do. I copy putty.exe around all of the time.[/color]

                    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.
                    [color=blue][color=green]
                    >> Do you know of any other program that behaves like that?[/color]
                    >
                    > Back in the day, that used to be fairly common under
                    > DOS/Windows. Not that it's still not a really bad idea.[/color]

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

                    Diez

                    Comment

                    • SuperHik

                      #11
                      Re: saving settings

                      Diez B. Roggisch wrote:[color=blue]
                      > Grant Edwards wrote:
                      >
                      >[color=green]
                      >> Documents and settings aren't quite the same thing, but it's a
                      >> valid point.
                      >>[color=darkred]
                      >>> Especially not the ones you wrote on that other machine.
                      >>>
                      >>> Seriously: Who is going to copy a executable around?[/color]
                      >> I do. I copy putty.exe around all of the time.[/color]
                      >
                      > 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.
                      >[color=green][color=darkred]
                      >>> Do you know of any other program that behaves like that?[/color]
                      >> Back in the day, that used to be fairly common under
                      >> DOS/Windows. Not that it's still not a really bad idea.[/color]
                      >
                      > Back in the day self-modifying code was the craze too. And _some_ people
                      > even do it in python :)[/color]
                      those crazy bastards! ;)[color=blue]
                      >
                      > Diez[/color]

                      Comment

                      • Ten

                        #12
                        Re: saving settings

                        On Monday 29 May 2006 12:28, SuperHik wrote:[color=blue]
                        > aum wrote:[color=green]
                        > > On Mon, 29 May 2006 09:05:36 +0200, SuperHik wrote:[color=darkred]
                        > >> 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![/color]
                        > >
                        > > Yikes!!!
                        > >
                        > > I'd strongly suggest you read the doco for ConfigParser, and load/save
                        > > your config file to/from os.path.join(os .path.expanduse r("~")).
                        > >
                        > > Another option - save your stuff in the Windows Registry[/color]
                        >
                        > but if I copy this file on the other computer settings will be lost...[/color]

                        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.
                        --
                        There are 10 types of people in this world,
                        those who understand binary, and those who don't.

                        Comment

                        Working...