Generating list of possible configurations

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • bjorklund.emil@gmail.com

    Generating list of possible configurations

    Hello pythonistas.

    I'm a newbie to pretty much both programming and Python. I have a task
    that involves writing a test script for every possible combination of
    preference settings for a software I'm testing. I figured that this
    was something that a script could probably do pretty easily, given all
    the various possibilites.

    I started creating a dictionary of all the settings, where each key
    has a value that is a list of the possible values for that setting.
    Most of the settings are simple booleans (setting is on or off), some
    of them are drop-downs with several values. For example:

    settings = {
    'setting_a': (True, False),
    'setting_b': (True, False),
    'setting_c': (1, 2, 3, 4),
    }

    After this I tried figuring out a function that would generate the
    different possible configurations, but I couldn't quite wrap my head
    around it... Are there any general patterns/structures that are suited
    for this type of task? Any pointers as to how one would go about
    solving something like this would be greatly appreciated. It's not
    that I really need to use Python for it, but I thought it could be a
    good learning excercise... :-)

    Kind regards,
    //Emil
  • Mensanator

    #2
    Re: Generating list of possible configurations

    On Jul 2, 4:53 pm, "bjorklund.e... @gmail.com"
    <bjorklund.e... @gmail.comwrote :
    Hello pythonistas.
    >
    I'm a newbie to pretty much both programming and Python. I have a task
    that involves writing a test script for every possible combination of
    preference settings for a software I'm testing. I figured that this
    was something that a script could probably do pretty easily, given all
    the various possibilites.
    >
    I started creating a dictionary of all the settings, where each key
    has a value that is a list of the possible values for that setting.
    Most of the settings are simple booleans (setting is on or off), some
    of them are drop-downs with several values. For example:
    >
    settings = {
        'setting_a': (True, False),
        'setting_b': (True, False),
        'setting_c': (1, 2, 3, 4),
    >
    }
    >
    After this I tried figuring out a function that would generate the
    different possible configurations, but I couldn't quite wrap my head
    around it...
    Basically, for each setting of a, you must do each possible b,
    and for each a,b setting you must do each possible c, etc.
    Are there any general patterns/structures that are suited
    for this type of task?
    Lookup "Cartesian Product".
    Any pointers as to how one would go about
    solving something like this would be greatly appreciated.
    for a in [True,False]:
    for b in [True,False]:
    for c in [1,2,3,4]:
    print 'combined settings:',a,'\ t',b,'\t',c

    combined settings: True True 1
    combined settings: True True 2
    combined settings: True True 3
    combined settings: True True 4
    combined settings: True False 1
    combined settings: True False 2
    combined settings: True False 3
    combined settings: True False 4
    combined settings: False True 1
    combined settings: False True 2
    combined settings: False True 3
    combined settings: False True 4
    combined settings: False False 1
    combined settings: False False 2
    combined settings: False False 3
    combined settings: False False 4

    It's not
    that I really need to use Python for it, but I thought it could be a
    good learning excercise... :-)
    You may, then, also be interested in

    Permutations with Replacement
    Permutations without Replacement
    Combinations with Replacement
    Combinations without Replacement
    >
    Kind regards,
    //Emil

    Comment

    • Terry Reedy

      #3
      Re: Generating list of possible configurations



      Mensanator wrote:
      On Jul 2, 4:53 pm, "bjorklund.e... @gmail.com"
      <bjorklund.e... @gmail.comwrote :
      >After this I tried figuring out a function that would generate the
      >different possible configurations, but I couldn't quite wrap my head
      >around it...
      Lookup "Cartesian Product".
      >
      >Any pointers as to how one would go about
      >solving something like this would be greatly appreciated.
      >
      for a in [True,False]:
      for b in [True,False]:
      for c in [1,2,3,4]:
      print 'combined settings:',a,'\ t',b,'\t',c
      This has been added to itertools at least for 2.6/3.0
      >>import itertools as it
      >>for prod in it.product((Tru e,False), (True,False), (1,2,3,4)):
      print(prod) # or run test

      (True, True, 1)
      (True, True, 2)
      (True, True, 3)
      (True, True, 4)
      (True, False, 1)
      (True, False, 2)
      (True, False, 3)
      (True, False, 4)
      (False, True, 1)
      (False, True, 2)
      (False, True, 3)
      (False, True, 4)
      (False, False, 1)
      (False, False, 2)
      (False, False, 3)
      (False, False, 4)

      The sequences of sequences can, of course, be a variable:
      >>options = ((True,False), (True,False), (1,2,3,4))
      >>for prod in it.product(*opt ions): print(prod)
      does the same thing. So you can change 'options' without changing the
      test runner.

      tjr

      Comment

      • Bruno Desthuilliers

        #4
        Re: Generating list of possible configurations

        Terry Reedy a écrit :
        >
        >
        Mensanator wrote:
        (snip)
        >Lookup "Cartesian Product".
        (snip)
        >for a in [True,False]:
        > for b in [True,False]:
        > for c in [1,2,3,4]:
        > print 'combined settings:',a,'\ t',b,'\t',c
        >
        This has been added to itertools at least for 2.6/3.0

        Great !

        Comment

        • Jeff

          #5
          Re: Generating list of possible configurations

          On Jul 2, 5:53 pm, "bjorklund.e... @gmail.com"
          <bjorklund.e... @gmail.comwrote :
          Hello pythonistas.
          >
          I'm a newbie to pretty much both programming and Python. I have a task
          that involves writing a test script for every possible combination of
          preference settings for a software I'm testing. I figured that this
          was something that a script could probably do pretty easily, given all
          the various possibilites.
          >
          I started creating a dictionary of all the settings, where each key
          has a value that is a list of the possible values for that setting.
          Most of the settings are simple booleans (setting is on or off), some
          of them are drop-downs with several values. For example:
          >
          settings = {
              'setting_a': (True, False),
              'setting_b': (True, False),
              'setting_c': (1, 2, 3, 4),
          >
          }
          >
          After this I tried figuring out a function that would generate the
          different possible configurations, but I couldn't quite wrap my head
          around it... Are there any general patterns/structures that are suited
          for this type of task? Any pointers as to how one would go about
          solving something like this would be greatly appreciated. It's not
          that I really need to use Python for it, but I thought it could be a
          good learning excercise... :-)
          >
          Kind regards,
          //Emil
          I recently needed the functionality in Python to take a series of lists and find all possible combinations of one item from each list. For example, take the

          Comment

          • Mensanator

            #6
            Re: Generating list of possible configurations

            On Jul 3, 2:13�am, Bruno Desthuilliers <bruno.
            42.desthuilli.. .@websiteburo.i nvalidwrote:
            Terry Reedy a �crit :
            >
            >
            >
            Mensanator wrote:
            (snip)
            Lookup "Cartesian Product".
            (snip)
            for a in [True,False]:
            � for b in [True,False]:
            � � for c in [1,2,3,4]:
            � � � print 'combined settings:',a,'\ t',b,'\t',c
            >
            This has been added to itertools at least for 2.6/3.0
            >
            Great !
            Well, it will be great at some point in the future
            when Python 2.6/3.0 have actually been released and
            third party extensions such as gmpy have caught up.

            Until then, such solutions are worthless, i.e., of
            no value.

            Comment

            • Terry Reedy

              #7
              Re: Generating list of possible configurations



              Mensanator wrote:
              On Jul 3, 2:13�am, Bruno Desthuilliers <bruno.
              42.desthuilli.. .@websiteburo.i nvalidwrote:
              >Terry Reedy a �crit :
              >>This has been added to itertools at least for 2.6/3.0
              >Great !
              >
              Well, it will be great at some point in the future
              when Python 2.6/3.0 have actually been released and
              The betas 'have actually been released' and I am happily using 3.0. The
              core features that I care about have mostly been untouched and where
              they have, they work.
              third party extensions such as gmpy have caught up.
              Not my personal concern. And certainly not a direct concern for nearly
              all uses of itertools.produ ct.
              Until then, such solutions are worthless, i.e., of no value.
              Why are you so anxious to generalize your personal negative views to
              everyone else. Worthless to you, worthwhile to me. And for someone who
              does not need cross-products today or in the next few months,
              potentially valuable information for when the final releases do arrive,
              maybe in September.

              tjr

              Comment

              • Mensanator

                #8
                Re: Generating list of possible configurations

                On Jul 3, 2:52 pm, Terry Reedy <tjre...@udel.e duwrote:
                Mensanator wrote:
                On Jul 3, 2:13�am, Bruno Desthuilliers <bruno.
                42.desthuilli.. .@websiteburo.i nvalidwrote:
                Terry Reedy a �crit :
                >This has been added to itertools at least for 2.6/3.0
                Great !
                >
                Well, it will be great at some point in the future
                when Python 2.6/3.0 have actually been released and
                >
                The betas 'have actually been released' and I am happily using 3.0.  
                But you're not using it for production work. Unless you're ignoring
                the recommendations .
                The
                core features that I care about have mostly been untouched and where
                they have, they work.
                That's not the issue.
                >
                third party extensions such as gmpy have caught up.
                >
                Not my personal concern.  
                Right. Which is why your 3.0 specific advice is worthless.
                Those ARE personal concerns of just about everyone else.
                And certainly not a direct concern for nearly
                all uses of itertools.produ ct.
                >
                Until then, such solutions are worthless, i.e., of no value.
                >
                Why are you so anxious to generalize your personal negative views to
                everyone else.  
                Not to everyone else, to the new and inexperienced Pyhton users.
                Maybe you don't remember what it was like being a new user where
                you need to have such things pointed out to you. And I'm not being
                negative, just realistic. If I ask a question today, I want an
                answer I can use tomorrow, not one I can use six months from now.
                Worthless to you, worthwhile to me.  
                The OP's opinion is the only one that matters. What do you suppose
                is the percentage of posts on this newsgroup by those using 3.0?
                And for someone who
                does not need cross-products today or in the next few months,
                potentially valuable information for when the final releases do arrive,
                maybe in September.
                That's fine for them. It's been said here that they will be a minority
                for a long time.
                >
                tjr

                Comment

                • George Sakkis

                  #9
                  Re: Generating list of possible configurations

                  On Jul 3, 5:49 pm, Mensanator <mensana...@aol .comwrote:
                  On Jul 3, 2:52 pm, Terry Reedy <tjre...@udel.e duwrote:
                  >
                  Worthless to you, worthwhile to me.  
                  >
                  The OP's opinion is the only one that matters.
                  I bet the OP doesn't know (or care) what gmpy is.
                  What do you suppose
                  is the percentage of posts on this newsgroup by those using 3.0?
                  Taking into account 2.6 too (we're not talking about only 3.0 here),
                  probably not much less than those who even know what is gmpy, let
                  alone dismiss a beta Python release because their obscure pet module
                  is not available yet.
                  You will probably sound less negative if you refrain from projecting
                  your own very specialized needs to those of the average pythonista.

                  George

                  Comment

                  • Mensanator

                    #10
                    Re: Generating list of possible configurations

                    On Jul 3, 6:24 pm, George Sakkis <george.sak...@ gmail.comwrote:
                    On Jul 3, 5:49 pm, Mensanator <mensana...@aol .comwrote:
                    >
                    On Jul 3, 2:52 pm, Terry Reedy <tjre...@udel.e duwrote:
                    >
                    Worthless to you, worthwhile to me.  
                    >
                    The OP's opinion is the only one that matters.
                    >
                    I bet the OP doesn't know (or care) what gmpy is.
                    But he'll care if he tries to use something specific to
                    2.6 and it fails and he doesn't know why.
                    >
                    What do you suppose
                    is the percentage of posts on this newsgroup by those using 3.0?
                    >
                    Taking into account 2.6 too (we're not talking about only 3.0 here),
                    probably not much less than those who even know what is gmpy, let
                    alone dismiss a beta Python release because their obscure pet module
                    is not available yet.
                    That was just an example. When you consider ALL the pet
                    modules like PIL, Numpy, Win32, etc., that's a lot, isn't it.
                    You will probably sound less negative if you refrain from projecting
                    your own very specialized needs to those of the average pythonista.
                    Funny how you don't complain when Mr. Reedy projects HIS
                    specialized needs to the average pythonista.

                    I was just trying to be helpful (I admit I often sound
                    negative when I'm not trying to be).
                    >
                    George

                    Comment

                    • casevh

                      #11
                      Re: Generating list of possible configurations

                      On Jul 3, 6:54 am, Mensanator <mensana...@aol .comwrote:
                      >
                      Well, it will be great at some point in the future
                      when Python 2.6/3.0 have actually been released and
                      third party extensions such as gmpy have caught up.
                      >
                      Until then, such solutions are worthless, i.e., of
                      no value.
                      gmpy is supported on Python 2.6. A new version and Windows binaries
                      were released shortly after 2.6b1 was released.

                      casevh

                      Comment

                      • George Sakkis

                        #12
                        Re: Generating list of possible configurations

                        On Jul 3, 7:51 pm, Mensanator <mensana...@aol .comwrote:
                        On Jul 3, 6:24 pm, George Sakkis <george.sak...@ gmail.comwrote:
                        >
                        Taking into account 2.6 too (we're not talking about only 3.0 here),
                        probably not much less than those who even know what is gmpy, let
                        alone dismiss a beta Python release because their obscure pet module
                        is not available yet.
                        >
                        That was just an example. When you consider ALL the pet
                        modules like PIL, Numpy, Win32, etc., that's a lot, isn't it.
                        A few points:
                        - The OP acknowledged he's a newbie, and as a newbie he'll probably
                        spend some time getting used to the language and the standard library
                        before jumping to the dozens 3rd party packages.
                        - I am sure many Python users are productive without ever touching an
                        external package; that is after all the point of "batteries included".
                        - Even if they do have external dependencies, chances are that they
                        are pure Python modules, which typically work without modification on
                        new 2.x versions.
                        I was just trying to be helpful (I admit I often sound
                        negative when I'm not trying to be).
                        Well, something like "Until then, such solutions are worthless, i.e.,
                        of no value" is too strong, subjective and biased to be really
                        helpful.

                        George

                        Comment

                        • Mensanator

                          #13
                          Re: Generating list of possible configurations

                          On Jul 3, 8:10�pm, casevh <cas...@gmail.c omwrote:
                          On Jul 3, 6:54�am, Mensanator <mensana...@aol .comwrote:
                          >
                          >
                          >
                          Well, it will be great at some point in the future
                          when Python 2.6/3.0 have actually been released and
                          third party extensions such as gmpy have caught up.
                          >
                          Until then, such solutions are worthless, i.e., of
                          no value.
                          >
                          gmpy is supported on Python 2.6. A new version and Windows binaries
                          were released shortly after 2.6b1 was released.
                          Great!

                          Looks like I'll be installing 2.6 this weekend.
                          >
                          casevh

                          Comment

                          • Mensanator

                            #14
                            Re: Generating list of possible configurations

                            On Jul 3, 9:09�pm, George Sakkis <george.sak...@ gmail.comwrote:
                            On Jul 3, 7:51 pm, Mensanator <mensana...@aol .comwrote:
                            >
                            On Jul 3, 6:24 pm, George Sakkis <george.sak...@ gmail.comwrote:
                            >
                            Taking into account 2.6 too (we're not talking about only 3.0 here),
                            probably not much less than those who even know what is gmpy, let
                            alone dismiss a beta Python release because their obscure pet module
                            is not available yet.
                            >
                            That was just an example. When you consider ALL the pet
                            modules like PIL, Numpy, Win32, etc., that's a lot, isn't it.
                            >
                            A few points:
                            - The OP acknowledged he's a newbie, and as a newbie he'll probably
                            spend some time getting used to the language and the standard library
                            before jumping to the dozens 3rd party packages.
                            - I am sure many Python users are productive without ever touching an
                            external package; that is after all the point of "batteries included".
                            - Even if they do have external dependencies, chances are that they
                            are pure Python modules, which typically work without modification on
                            new 2.x versions.
                            Yes, these points are valid, although I think
                            mine are valid also. But there's no point in any
                            further arguing.
                            >
                            I was just trying to be helpful (I admit I often sound
                            negative when I'm not trying to be).
                            >
                            Well, something like "Until then, such solutions are worthless, i.e.,
                            of no value" is too strong, subjective and biased to be really
                            helpful.
                            I was trying NOT to imply "broken" or "doesn't
                            do anything useful". I guess I'll have to try to
                            be less succinct.
                            >
                            George

                            Comment

                            • bjorklund.emil@gmail.com

                              #15
                              Re: Generating list of possible configurations

                              Wow, I didn't have time to look back on this thread for a while,
                              surprised of the activity. Anyhow, thanks for the answers, and thanks
                              for pointing out that the itertools-variants are not available in 2.5.

                              Cheers!

                              //emil

                              Comment

                              Working...