Python - if/else statements

dmbkiwi dmbkiwi at yahoo.com
Fri Jul 11 19:16:12 EDT 2003


On Fri, 11 Jul 2003 20:33:19 +0000, Bengt Richter wrote:

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

<snip>
Thanks for helping me with this.


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

They don't come from a module, they come from different functions within
the script.  To be honest, I don't think I've ever quite understood
globals, so I insert them where I think they should go - probably quite
incorrecly.  Will this matter?
 
> 
> # Second, are the globals accessible from multiple threads? Are you seeing
> hard-stuck errors or blue-moon errors?

Now my newbiness will be evident.  Multiple threads?  I am not consciously
creating threads.  Should I?  Does python automatically create multiple
threads?  What are hard-stuck/blue-moon errors?

> 
>>	if (meter == mainpic) and (button == 1):
> 		# always here?
		# yes
>>		if ddcon == 0:
> 			# and here ?
			# yes
>>			if ddon == 1:
> 				# and here?
				# no
>>				deleteDayDetail(widget, dayshow)
>>				karamba.redrawWidget(widget)
>>			createCurrentDetail(widget)
>>			karamba.redrawWidget(widget)
>>		else:
> 			# never here, you're saying, right?
			# always here
> 			# <snip>
>>	else:
> 		# never here either, right?
		always here
> 		# <snip>
> 	# get here though?
	# yes
>>	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

Tabs seem to be fine in the actual code - I think it's the word wrapping
in either your/my newsreader that is causing problems, but your tab
positioning is correct.

> indentation for me ;-) so I haven't used the tab checkers, but you might
> benefit, perhaps.

I'm using kate here under KDE/linux.  It has syntax highlighting for python, and
seems to deal with tabs nicely.
> 
>>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.

Why would these affect the interpretation of the if/else.  Seems to me,
that if the if statement evaluates to true, then the else statement should be
ignored.  However, it appears that for these users, python is just
ploughing right on through, and running the else statement also.  Or am I
missing something.  What is a mousetrap?

Any further help would be greatly appreciated.

> 
> Regards,
> Bengt Richter

-- 
Regards
Matt

Everyone is more or less mad on one point.
		-- Rudyard Kipling





More information about the Python-list mailing list