Python - if / else语句 [英] Python - if/else statements

查看:101
本文介绍了Python - if / else语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是这个小组的新手,而且相对较新的python编程,但是,

遇到了一个问题,我无法通过阅读

文档和搜索来解决这个群组在google上。


我在python上为kde上的superkaramba主题引擎写了一个主题

(参见 http://netdragon.sourceforge.net - 如果你是kde / linux用户,那就是

a伟大的视觉小程序引擎)。我已将其上传到 www.kdelook.org 以获取

其他人然而,下载和使用,有些用户遇到了问题,这对我来说似乎很奇怪。


基本上问题是他们的版本python忽略了一个

if / else语句,我不明白为什么。超过3000人已经下载了这个主题,只有3人发现了这个问题。

代码的相关部分是:


def meterClicked(小部件,仪表,按钮):

#print" meterclick" ;

全球日间节目,daypicrem,ddon,ddcon,按下

if(meter == mainpic)和(button == 1):

如果ddcon == 0:

如果ddon == 1:

deleteDayDetail(widget,dayshow)

karamba.redrawWidget(widget)

createCurrentDetail(widget)

karamba.redrawWidget(widget)

else:

deleteCurrentDetail(widget)

else:

for i in range(0,5):

if(meter == daypicrem [i])and(button == 1)and (dayshow!= i):

#print" buttonpressed:day" + str(i)

如果ddon == 1:

deleteDayDetail(widget,dayshow)

karamba.redrawWidget(widget)

elif ddcon == 1:

deleteCurrentDetail(widget)

karamba.redrawWidget(widget)

createDayDetail(widget,i )

karamba.redrawWidget(widget)

dayshow = i

#print dayshow

break

如果(米== daypicrem [i])和(按钮== 1)和(dayshow == i):

如果ddon == 1:

deleteDayDetail(widget,dayshow)

karamba.redrawWidget(widget)

elif ddcon == 1:

deleteCurrentDetail(widget)

karamba.redrawWidget(小部件)

dayshow = i

#print dayshow

break

buttonpressed = 1

这些用户正在经历的是这部分代码正在处理,并将所有if语句评估为true,但是,你可以

看,每次调用此函数时,它们都不可能都是真的。他们的
版本的python也忽略了else构造。


任何人都可以了解这些用户可能发生的事情吗?


马特

解决方案

2003年7月12日星期六07:34:18 +1200,dmbkiwi< dm *** **@yahoo.com>写道:

我是这个小组的新手,而且相对较新的python编程,但是,
遇到了一个问题,我只是无法通过阅读
文档来解决,并在谷歌搜索这个组。

我已经在python上为kde上的superkaramba主题引擎写了一个主题
(参见 http://netdragon.sourceforge.net - 如果您是kde / linux用户,那么它是一个很棒的可视化applet引擎。我已将其上传到 www.kdelook.org ,供其他人下载和使用但是,有些用户遇到了问题,对我来说似乎很奇怪。

基本上问题是他们的python版本忽略了
if / else声明,我不明白为什么。超过3000人已经下载了主题,只有3人发现了这个问题。相关的代码部分是:

def meterClicked(小部件,仪表,按钮):
#print" meterclick"
全球日间节目,daypicrem,ddon, ddcon,按下
#这些全局变量 - 它们来自哪里?什么模块?

#注意每个模块都有自己的全局变量,所以是否有不同的模块

#认为他们正在分享全局变量但是真的不是?有办法解决这个问题,

#但首先是相关的吗?


#第二,是否可以从多个线程访问全局变量?您是否看到了难以理解的

错误或蓝月错误?

if(meter == mainpic)and(button == 1):
#always这里?如果ddcon == 0:
#和这里?如果ddon == 1:
#和这里? deleteDayDetail(widget,dayshow)
karamba.redrawWidget(widget)
createCurrentDetail(widget)
karamba.redrawWidget(widget)
否则:
#never never,you'说,对吧?

#< snip>否则:
#从来没有在这里,对吧?

#< snip>

#到此为止? buttonpressed = 1

我用上面的标签排列(也许;-)和你的文字,但也许你应该

通过tabnanny运行你的代码或检查一致性用法。

我从不使用标签(虽然我使用tab键和gvim为我添加4个空格缩进;-)

因此我没有使用标签或许,你可能会受益。

这些用户正在经历的是这部分代码正在处理,并将所有if语句评估为真,但是,你可以<看,每次调用这个函数时,它们都不可能都是真的。他们的python版本也忽略了else构造。

任何人都可以了解这些用户可能发生的事情吗?



I首先检查全局和线程问题。然后看看建造

a捕鼠器。


问候,

Bengt Richter


On Fri,2003年7月11日20:33:19 +0000,Bengt Richter写道:

2003年7月12日星期六07:34:18 +1200,dmbkiwi< dm*****@yahoo.com>写道:


< snip>

感谢您帮助我。

< blockquote class =post_quotes> def meterClicked(widget,meter,button):
#print" meterclick"
global dayshow,daypicrem,ddon,ddcon,buttonpressed


#这些全局变量 - 它们来自哪里?什么模块? #注意每个
模块都有自己的全局变量,所以有不同的模块#认为它们正在共享全局变量但是真的不是吗?有办法解决这个问题,#
但首先是相关的吗?




他们不是来自一个模块,他们来自不同的功能

脚本内。老实说,我不认为我已经完全理解了全局,所以我把它们插入到我认为它们应该去的地方 - 可能相当于

。这有关吗?

#第二,是否可以从多个线程访问全局变量?您是否看到了难以卡住的错误或蓝月错误?


现在,我的新生活将会很明显。多线程?我并不是有意识地创建线程。我是不是该? python会自动创建多个

个线程吗?什么是困难/蓝月亮错误?

if(meter == mainpic)和(button == 1):#always here?



#yes

如果ddcon == 0:


#和这里?



#yes

if ddon == 1:


#and here?



#no

deleteDayDetail(widget,dayshow)
karamba.redrawWidget(widget)
createCurrentDetail(widget)
karamba.redrawWidget(小部件)
其他:


#从不在这里,你说,对吗?



#always here#< snip>

其他:#从不在这里,对吗?



总是在这里#< snip>
#到此为止?
#yes

buttonpressed = 1


我使用上面的标签排列(也许;-)和你的文字,但是也许你应该通过tabnanny运行你的代码或者检查一致的
用法。我从不使用标签(虽然我使用tab键和gvim放入4个空格




标签在实际代码中看起来很好 - 我认为它是'在你的/我的新闻阅读器中,你的/我的新闻阅读器中的
导致问题,但你的标签

定位是正确的。

缩进对我来说;-)所以我没有使用标签检查器,但也许你可能会受益。


我在KDE / linux下使用kate。它有python的语法高亮,并且

似乎很好地处理了标签。

这些用户正在经历的是这部分代码正在被处理,并且将所有if语句评估为true,但是,正如您所看到的,每次调用此函数时,它们都不可能都是真的。他们的python版本也忽略了else构造。

任何人都可以了解这些用户可能发生的事情吗?
我会检查全局和线程问题首先。然后看看
构建一个捕鼠器。




为什么它们会影响if / else的解释。在我看来,

如果if语句的计算结果为true,则else语句应该被忽略。但是,看起来对于这些用户来说,python只是直接通过,并且还运行了else语句。或者我是否b $ b缺少一些东西。什么是捕鼠器?


任何进一步的帮助将不胜感激。

问候,
Bengt Richter




-

问候

马特


每个人都或多或少地生气。

- Rudyard Kipling


2003年7月12日星期六11:16:12 +1200,dmbkiwi< dm ** ***@yahoo.com>写道:

2003年7月11日星期五20:33:19 +0000,Bengt Richter写道:

2003年7月12日星期六07:34:18 +1200,dmbkiwi< dm ***** @ yahoo.com>写道:

< snip>
感谢您帮助我。

def meterClicked(小部件,仪表,按钮):
#print" meterclick"
global dayshow,daypicrem,ddon,ddcon,buttonpressed


#这些全局变量 - 它们来自哪里从?什么模块? #注意每个
模块都有自己的全局变量,所以有不同的模块#认为它们正在共享全局变量但是真的不是吗?有办法解决这个问题,#
但首先是相关的吗?



他们不是来自一个模块,他们来自不同的职能部门>脚本。说实话,我不认为我已经完全理解了全局,所以我将它们插入到我认为它们应该去的地方 - 可能非常相当
。这有关系吗?



它可以。这取决于。导入的脚本或文件(扩展名可能会有所不同,.py,.pyc等)

就像一个带有单个软木公告板的大房间。将该公告板视为脚本'或模块'的全局名称空间。这是名称标签可以添加名称

与对象相关联的地方。您可以将物体本身视为气球附加到

名称标记为字符串(房屋没有屋顶,因此所有气球占据空间

外面的某处高处; - )


请注意,根据这个模型,当你指定x = y时,你b $ b正在做的是找到y-labled标签并跟随它的字符串到关联的对象气球

并将一个新字符串绑定到同一个气球,然后将该新字符串附加到标记为x的

新标记并在此处添加此新标记一个合适的公告牌,导致两个标签和他们的琴弦通向相同的物体气球。


功能就像大房间内的游戏屋,并且它们每个都有自己的

公告牌,这是每个函数的本地命名空间。


如果你写global xxx在一个函数中,你说当你在那个

剧场时,你不会在内部的私人公告牌上使用标有xxx的名称标签,

但你会改为伸出手,在大房间里使用公告牌。所以xxx = 123

表示创建一个带有123值的整数对象气球,并制作一个标记为xxx的标签,并且

将123气球中的一个字符串绑定到该标签,然后伸出并将标签贴在大房间的

公告牌上。


当你离开剧场时,它的内部公告牌上没有名字标签(和

字符串分离)。当你再次输入时,你开始使用一个干净的内部板,只有

名称标签匹配形式参数名称(如果有的话)。如果最后一个字符串是分离的,那么它会被一个气球收集器抓住,它会弹出它以确保新气球的天空中总有空间。种类;-)


如果你不写全球xxx在函数内部,标记为

xxx的名称标签的规则根据函数

中是否有任何代码_anywhere_来修复该名称标签(例如,指定该名称)或代码只是

查找现有标签(即,只在表达式中使用它)。


如果有'这是一个任务,在分配之前尝试在表达式

中使用它是错误的。合法的任务将标签粘贴到内部公告板上。

无论标签在哪里,气球和字符串部分都是相同的故事。


如果有''没有任务,那么唯一的其他普通方式就可以在内部bb

如果它是一个参数名称,或者它被一些其他代码固定名称标签,
就像def foo ...会生成一个foo名称标签(字符串转到一个函数对象),或类Bar ...

这将使一个带有字符串的Bar name标签到一个类对象。这些是主要方式。


如果名称标签不在内部bb,它仍然可以在封闭的剧场'

公告板上(它现在可以嵌套游戏屋,而不仅仅是将它们放在大房间里。

如果在紧邻的游戏屋的bb上找不到名称标签,它可能在

另一个封闭的剧场的bb,依此类推,直到在大公共房间的b / b
上找不到它,这是一个名字错误。


顺便说一句,字符串的名称标签末端也可以绑在一些气球上,这些气球可能有特殊的b
小孔贴在他们身上。例如,元组气球进来了根据他们将琴弦连接到其他气球的固定孔数量的变化。在元组的情况下,孔眼

是一次性使用。你不能切割并重新绑定一根绳子,你必须制作一个新的元组气球

并绑定你想要的字符串。如果你切断了最后一根串起一个元组气球,

气球收藏家将抓住它并最终切断所有琴弦并弹出元组气球,

可能马上。他可能与气球制造商就回收材料进行秘密交易,但这是他的事。 List-ballons允许孔眼重复使用,并且还可以添加或移除孔眼。

但是每个孔眼都必须有一个通向某个气球的绳子,即使它是无气球。


#第二,是否可以从多个线程访问全局变量?您是否看到了难以卡住的错误或蓝月亮错误?
现在我的新生活将会很明显。多线程?我不是有意识地创建线程。我是不是该? python会自动创建多个
线程吗?什么是困难/蓝月亮错误?



你不应该有多个线程,除非你故意制作它们或使用一些

模块没有你知道就做到了。如果是这样,它应该在文档中突出。

硬卡/蓝月不是技术术语;-)我的意思是,你得到错误

每次执行代码,或者只在蓝色月亮执行一次。

if(meter == mainpic)and(button == 1):#always here?


#yes

如果ddcon == 0:


#和这里?


#yes

如果ddon == 1:


#和这里?


#no



#所以至少有一个如果没有''通过''!

deleteDayDetail(widget,dayshow)
karamba.redrawWidget(widget)
createCurrentDetail(widget)
karamba.redrawWidget(widget)
else:
#从不在这里,你说,对吧?


#always here



#非常奇怪。有什么证据可以解释这些结论?

#< snip>

else:


#从不在这里,对吧?


总是在这里



#再次奇怪** n

#< snip>
#到此为止?


#yes

buttonpressed = 1

如果真的发生这种情况,我想知道你是不是以某种方式从不同的版本执行代码

或者进行某种混合安装。或者使用不兼容的扩展模块?

您是否安装了多个版本?你的版本是什么,sym链接是什么?

什么是#!你的脚本行?

我用上面的标签排列(也许;-)和你的文字,但也许你应该运行你的代码通过tabnanny或其他东西来检查一致的
用法。我从不使用标签(虽然我使用tab键和gvim放入4个空格



标签在实际代码中似乎没问题 - 我认为它是包装的词/>在您的/我的新闻阅读器中导致问题,但您的标签定位是正确的。

缩进​​对我来说;-)所以我没有使用过选项卡跳棋,但你可能也会受益。



我在KDE / linux下使用kate。它有python的语法高亮,并且
似乎很好地处理了选项卡。

这些用户正在经历的是这部分代码是
处理,并将所有if语句评估为true,但是,正如您所看到的,每次调用此函数时,它们都不可能都是真的。他们的python版本也忽略了else构造。



他们的版本?这是否意味着您尝试使用不同的版本解释器运行扩展名或.pyc代码

?那应该不行。 Python源代码(.py)

应该可以工作,除非旧的解释器遇到一个它不知道的新功能。

任何人都可以了解可能的内容继续这些用户?


我会先检查全局和线程问题。然后看看
构建一个捕鼠器。



为什么这些会影响if / else的解释。在我看来,
如果if语句的计算结果为true,则应忽略else语句。然而,看起来对于这些用户来说,python只是



当然,我猜,我真的不相信我在读什么。抱歉。我认为

条件数据被破坏了,而不是条件机器。

正在通过,并运行else语句。或者我错过了什么。什么是捕鼠器?
通过捕鼠器我的意思是插入一些测试代码以隐藏问题鼠标,比喻说。

任何进一步的帮助将不胜感激。



我猜测版本冲突或一些安装腐败最有可能来自这里。

得走了......


问候,

Bengt Richter


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 http://netdragon.sourceforge.net - if you are a kde/linux user, it is
a great visual applet engine). I have uploaded it to www.kdelook.org 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
if (meter == mainpic) and (button == 1):
if ddcon == 0:
if ddon == 1:
deleteDayDetail(widget, dayshow)
karamba.redrawWidget(widget)
createCurrentDetail(widget)
karamba.redrawWidget(widget)
else:
deleteCurrentDetail(widget)
else:
for i in range(0,5):
if (meter == daypicrem[i]) and (button == 1) and (dayshow != i):
#print "buttonpressed: day" + str(i)
if ddon == 1:
deleteDayDetail(widget, dayshow)
karamba.redrawWidget(widget)
elif ddcon == 1:
deleteCurrentDetail(widget)
karamba.redrawWidget(widget)
createDayDetail(widget, i)
karamba.redrawWidget(widget)
dayshow = i
#print dayshow
break
if (meter == daypicrem[i]) and (button == 1) and (dayshow == i):
if ddon == 1:
deleteDayDetail(widget, dayshow)
karamba.redrawWidget(widget)
elif ddcon == 1:
deleteCurrentDetail(widget)
karamba.redrawWidget(widget)
dayshow = i
#print dayshow
break
buttonpressed = 1
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?

Matt

解决方案

On Sat, 12 Jul 2003 07:34:18 +1200, dmbkiwi <dm*****@yahoo.com> 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 http://netdragon.sourceforge.net - if you are a kde/linux user, it is
a great visual applet engine). I have uploaded it to www.kdelook.org 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.

Regards,
Bengt Richter


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

On Sat, 12 Jul 2003 07:34:18 +1200, dmbkiwi <dm*****@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


On Sat, 12 Jul 2003 11:16:12 +1200, dmbkiwi <dm*****@yahoo.com> wrote:

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

On Sat, 12 Jul 2003 07:34:18 +1200, dmbkiwi <dm*****@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?


It could. It depends. A script or a file (extension may vary, .py, .pyc, etc) that''s imported
is like a big room with a single cork bulletin board. Think of that bulletin board as
the script''s or module''s global name space. It''s where name tags can be tacked up with names
associated with objects. You can think of the objects themselves as balloons attached to
the name tags by strings (the houses have no roofs, so all the balloons occupy space
someplace high up outside ;-)

Note that according to this model, when you assign x=y what you
are doing is finding the y-labled tag and following its string to the associated object-balloon
and tying a new string to that same balloon, and then attaching that new string to a
new tag labeled x and tacking this new tag on an appropriate bulletin board, resulting in
two tags and their strings leading to the same object-balloon.

Functions are like play houses inside the big room, and they each have their own
bulletin boards inside, which is each function''s local namespace.

If you write "global xxx" inside a function, you are saying that when you are in that
playhouse, you will not use the inside private bulletin board for name tags labeled xxx,
but you will instead reach out and use the bulletin board in the big room. So xxx=123
means create an integer object-balloon with 123 value and make a tag labeled xxx and
tie a string from the 123 balloon to that tag, and then reach out and tack the tag to the
bulletin board in the big room.

When you leave the playhouse, its inside bulletin board is cleared of name tags (and the
strings detached). When you enter again, you start with a clean inside board with only
name tags matching the formal parameter names (if any). If the last string is detached,
it is grabbed by a balloon collector, who pops it to make sure there is always space in
the sky for new balloons. Kind of ;-)

If you don''t write "global xxx" inside the function, the rules for name tags labeled
xxx are different according to whether there''s any code _anywhere_ in the function
that tacks up that name tag (e.g., assigns to that name) or whether the code just
looks for an existing tag (i.e., just uses it in an expression).

If there''s an assignment anywhere, it''s an error to try to use it in an expression
before the assignment. A legal assignment tacks the tag to the inside bulletin board.
The balloon and string part is the same story wherever the tag goes.

If there''s no assignment, then the only other ordinary way it can be on the inside bb
is if it is a parameter name, or it got tacked there by some other code that tacks name tags,
like def foo... will make a foo name tag (the string goes to a function object), or class Bar...
which would make a Bar name tag with string to a class object. Those are the main ways.

If the name tag is not on the inside bb, it could still be on an enclosing playhouse''s
bulletin board (it is now possible to nest playhouses, not just have them all in the big room.
If the name tag is not found on the bb of the immediately enclosing playhouse, it could be on
the bb of yet another enclosing playhouse, and so on, until if it is not found on the bb of
the big common room, it''s a name error.

BTW, the name-tag end of strings can also be tied to some balloons, which may have special
eyelets taped to them. E.g., tuple-balloons come in variations according to how many fixed
eyelets they have for attaching strings to other balloons. In the case of tuples, the eyelets
are single-use. You can''t cut and re-tie a single string, you have to make a new tuple-balloon
and tie what strings you want there. If you cut the last string to a tuple-balloon, the
baloon collector will grab it and eventually cut all the strings and pop the tuple-balloon,
maybe right away. He may have secret deals with balloon makers for recycling material, but
that''s his business. List-ballons allow eyelet re-use, and also adding or removing eyelets.
But every eyelet must have a string leading to some balloon, even if it is the None balloon.


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


You shouldn''t have multiple threads unless you made them on purpose or used some
module that did it without your knowing. It should be prominent in the docs if so, though.
Hard-stuck/blue-moon is not technical terminology ;-) I meant, do you get the error
every time the code is executed, or only once in a blue moon.

if (meter == mainpic) and (button == 1): # always here?


# yes

if ddcon == 0:


# and here ?


# yes

if ddon == 1:


# and here?


# no


# so at least one if didn''t just ''fall through''!

deleteDayDetail(widget, dayshow)
karamba.redrawWidget(widget)
createCurrentDetail(widget)
karamba.redrawWidget(widget)
else:


# never here, you''re saying, right?


# always here


# very very weird. What evidence are you interpreting to come to these conclusions?

# <snip>

else:


# never here either, right?


always here


# again weird**n

# <snip>
# get here though?


# yes

buttonpressed = 1
If that is really happening, I wonder if you are somehow executing code from a different version
or have some kind of mixed-up installation. Or are using incompatible extension modules?
Do you have multiple versions installed? what are your versions, and what sym links are there?
And what are the #! lines of your script(s)?

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.


Their versions? Does that mean you are trying to run extensions or .pyc code
with different version interpreters? That shouldn''t work. Python source (.py)
should work, unless an old interpreter runs into a new feature it doesn''t know about.
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


Sure, I didn''t really believe what I was reading, I guess. Sorry. I thought
the condition data was getting clobbered, not the condition machinery.
ploughing right on through, and running the else statement also. Or am I
missing something. What is a mousetrap? By mousetrap I meant some test code inserted to trap the problem mouse, metaphorically speaking.

Any further help would be greatly appreciated.


I guess version clash or some installation corruption looks most likely from here.
Gotta go...

Regards,
Bengt Richter


这篇关于Python - if / else语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆