2Qs

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

    #1

    2Qs

    1st question:

    If a make an exe with i.e. py2exe, can I get any kind of error/bug
    report from the exe file saved into a file error.log and how?

    2nd question:

    is there a better way to do this:

    <code>
    def tritup(x,y,z):
    #here is a while loop giving 3 results, i.e. r1,r2,r3
    return r1,r2,r3

    #I want to put sum of r1,r2,r3 as a condition in if statement
    #so I created a function to do this, but I can't escape a feeling
    #there is a more elegant solution, especially in python ;=)

    def summm(a,b,c):
    return a+b+c

    if x>10 and y>10 and z>10 and summ(tritup(x,y ,z)): print "OK"
  • bearophileHUGS@lycos.com

    #2
    Re: 2Qs

    SuperHik, for the second question there is builtin sum():
    [color=blue][color=green][color=darkred]
    >>> values = 10.5, 5, -12
    >>> sum(values)[/color][/color][/color]
    3.5

    Your if becomes:

    if x>10 and y>10 and z>10 and sum(tritup(x,y, z)):
    print "OK"

    Bye,
    bearophile

    Comment

    • Diez B. Roggisch

      #3
      Re: 2Qs

      if x>10 and y>10 and z>10 and sum((x,y,z)): print "OK"

      Diez

      Comment

      • Steven D'Aprano

        #4
        Re: 2Qs

        On Sat, 24 Jun 2006 21:24:33 +0200, SuperHik wrote:
        [color=blue]
        > 1st question:
        >
        > If a make an exe with i.e. py2exe, can I get any kind of error/bug
        > report from the exe file saved into a file error.log and how?[/color]

        Write the program to write a log file as it runs?


        [color=blue]
        > 2nd question:[/color]
        [snip][color=blue]
        > if x>10 and y>10 and z>10 and summ(tritup(x,y ,z)): print "OK"[/color]

        Others have already suggested you use the built-in sum() function.

        I'll suggest you don't need it at all, because it is redundant.

        If the sum is zero, either all three values are zero or at least one of
        the values is negative. In either case the first test will fail.

        There are no circumstances where each of x, y and z are greater than 10
        but the sum is zero; nor are there any circumstances where the sum is
        zero but x, y and z are still all greater than 10.



        --
        Steven.

        Comment

        • Cameron Laird

          #5
          Re: 2Qs

          In article <e7k3hk$560$1@s s408.t-com.hr>,
          SuperHik <junkytownMAKNI @gmail.com> wrote:[color=blue]
          >1st question:
          >
          >If a make an exe with i.e. py2exe, can I get any kind of error/bug
          >report from the exe file saved into a file error.log and how?[/color]

          Comment

          • JW

            #6
            Re: 2Qs

            > > 2nd question:[color=blue]
            > [snip][color=green]
            > > if x>10 and y>10 and z>10 and summ(tritup(x,y ,z)): print "OK"[/color]
            >
            > Others have already suggested you use the built-in sum() function.
            >
            > I'll suggest you don't need it at all, because it is redundant.
            >
            > If the sum is zero, either all three values are zero or at least one of
            > the values is negative. In either case the first test will fail.
            >
            > There are no circumstances where each of x, y and z are greater than 10
            > but the sum is zero; nor are there any circumstances where the sum is
            > zero but x, y and z are still all greater than 10.[/color]

            Unless, of course, the function tritup returns negative values. My
            guess is that the "> 10" tests are protecting the tritup function, and
            possibly should be moved there. Without the details of the function, I
            can't tell, but it may be incorrect to remove those tests.

            Which brings us to the other bit of advice - unit tests protect you
            from yourself and from those who optimize too quickly.

            Comment

            Working...