2Qs

S

SuperHik

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"
 
B

bearophileHUGS

SuperHik, for the second question there is builtin sum():
3.5

Your if becomes:

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

Bye,
bearophile
 
C

Cameron Laird

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?
.
.
.
Yes.

It's hard to know what more to say, in the absence of knowledge about
your background. I *think* what you're after is this: define a

import sys

def main():
# All the real work starts here.
do_first_important_thing()
do_more()
still_more()
finish_it_all()

try:
main()
except:
problem = sys.exc_info()
fp = open("error.log", "w")
fp.write("The problem was '%s'.\n", str(problem[1]))
fp.close()
 
S

Steven D'Aprano

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?

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


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

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.
 
D

Dennis Lee Bieber

if x>10 and y>10 and z>10 and sum((x,y,z)): print "OK"
Of course, given the first three conditions, the last is a waste of
time... The sum of three positives (non-zero) values, much less three
that are > 10, is going to be a positive value itself.
--
Wulfraed Dennis Lee Bieber KD6MOG
(e-mail address removed) (e-mail address removed)
HTTP://wlfraed.home.netcom.com/
(Bestiaria Support Staff: (e-mail address removed))
HTTP://www.bestiaria.com/
 
J

JW

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

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.

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.
 

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
474,431
Messages
2,571,678
Members
48,796
Latest member
Greg L.

Latest Threads

Top