Opening an exe

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • bartonc
    Recognized Expert Expert
    • Sep 2006
    • 6478

    #16
    Originally posted by defience
    Thank you both for your replies! One more thing.....how could I do this:
    Code:
    i = 0
    for i in range(0,30):
         print i
         i +=1
    ....have the double digits print out with a space between them:
    2 0
    2 1
    2 2 etc...

    Would something like this work? i = 0 0?
    Code:
    I don't see where the "2" is coming from in your example.
    Print will put a space in for you by using the comma.
    range() takes (start, [stop], [step]) where braces mean optional parameters.
    for i in range(30):
         print 2, i

    Comment

    • dshimer
      Recognized Expert New Member
      • Dec 2006
      • 136

      #17
      I'll agree with bartonc that I'm not totally positive what you are trying to accomplish, but a quick review of for and range may help.

      You don't need to set i=0 because in the
      Code:
       for i in range(30):
      a start of 0 is implied, though if you need to reset it you can just say
      Code:
       for i in range(0,30):
      range is just creating a list of numbers, each member of which gets evaluated as i during the loop.
      Code:
      >>> range(5)
      [0, 1, 2, 3, 4]
      so it has always seemed to me to be dangerous to modify it inside the loop. Though there may be good reasons to do so.

      To reproduce the output you listed
      Code:
      >>> for i in range(3):
      ... 	print 2,i
      ... 	
      2 0
      2 1
      2 2
      though I didn't take it to 30.

      Comment

      • defience
        New Member
        • Jan 2007
        • 27

        #18
        The 2 in the example was just a reference to numbers in the twenties,ie
        20
        21
        22
        but I want them to print out with a space:
        2 0
        2 1
        2 2

        Comment

        • dshimer
          Recognized Expert New Member
          • Dec 2006
          • 136

          #19
          In the single digit numbers do you still need 2 numbers? For example...
          0 0
          0 1
          0 2

          Comment

          • dshimer
            Recognized Expert New Member
            • Dec 2006
            • 136

            #20
            Just in case, this may not be pretty because I have one foot out the door, but.
            Code:
            >>> for i in range(15):
            ... 	num='%02d'%i
            ... 	print num[0],num[1]
            0 0
            0 1
            0 2
            0 3
            0 4
            0 5
            0 6
            0 7
            0 8
            0 9
            1 0
            1 1
            1 2
            1 3
            1 4

            Comment

            • defience
              New Member
              • Jan 2007
              • 27

              #21
              Not pretty?? I think it's beautiful ;) Thanks again to the both of you! I really appreciate your knowledge.

              Comment

              • defience
                New Member
                • Jan 2007
                • 27

                #22
                This is my last hang up with this......tryin g to get the app.exe to run with every number in range.

                C:\python25>app .exe 0 0 1
                C:\python25>app .exe 0 0 2

                I guess I need to somehow loop the app.exe as well?

                Comment

                • bartonc
                  Recognized Expert Expert
                  • Sep 2006
                  • 6478

                  #23
                  Originally posted by defience
                  This is my last hang up with this......tryin g to get the app.exe to run with every number in range.

                  C:\python25>app .exe 0 0 1
                  C:\python25>app .exe 0 0 2

                  I guess I need to somehow loop the app.exe as well?
                  I haven't read the docs so there may be a way to pass args to app.exe in the call. Also, I haven't really been following along too well and you haven't posted a lot of working code of your own. One possible way to do this might be:
                  Code:
                  cmd = 'c:/unix/find.exe %s %s' %(num[0], num[1])
                  os.spawnv(os.P_WAIT, cmd, ['find', '/tmp'])

                  Comment

                  Working...