Python - if/else statements

Bengt Richter bokr at
Fri Jul 11 22:33:19 CEST 2003

On Sat, 12 Jul 2003 07:34:18 +1200, dmbkiwi <dmbkiwi at> wrote:

>I am new to this group, and relatively new to python programming, however,
>have encountered a problem I just cannot solve through reading the
>documentation, and searching this group on google.
>I have written a theme in python for the superkaramba theme engine on kde
>(see - if you are a kde/linux user, it is
>a great visual applet engine).  I have uploaded it to for
>others to download and use, however, some users are having an issue, which
>to me seems to be very strange.
>Basically the problem is that their version of python is ignoring an
>if/else statement, and I can't understand why.  Over 3000 people have
>downloaded the theme, and only 3 people have identified this problem.  The
>relevant portion of code is:
>def meterClicked(widget, meter, button):
>	#print "meterclick"
>	global dayshow, daypicrem, ddon, ddcon, buttonpressed
# these globals -- where do they come from? What module?
# Note that each module has its own globals, so is are there different modules
# that think they're sharing globals but really aren't? There are ways to solve that,
# but first, is that relevant?

# Second, are the globals accessible from multiple threads? Are you seeing hard-stuck
errors or blue-moon errors?

>	if (meter == mainpic) and (button == 1):
		# always here?
>		if ddcon == 0:
			# and here ?
>			if ddon == 1:
				# and here?
>				deleteDayDetail(widget, dayshow)
>				karamba.redrawWidget(widget)
>			createCurrentDetail(widget)
>			karamba.redrawWidget(widget)
>		else:
			# never here, you're saying, right?
			# <snip>
>	else:
		# never here either, right?
		# <snip>
	# get here though?
>	buttonpressed = 1
I used tabs above to line up (maybe ;-) with your text, but maybe you should
run your code through tabnanny or something to check for consistent usage.
I never use tabs (though I use the tab key and gvim puts in 4 space indentation for me ;-)
so I haven't used the tab checkers, but you might benefit, perhaps.

>What these users are experiencing is that this portion of code is being
>processed, and evaluating all if statements as true, however, as you can
>see, they cannot all be true each time this function is called.  Their
>versions of python also ignore the else construct.
>Can anyone shed any light on what might be going on with these users?
I'd check on the globals and threading issues first. Then see about building
a mousetrap.

Bengt Richter

More information about the Python-list mailing list