检查集合的布尔值 [英] Checking the boolean value of a collection
问题描述
大家好。
在我的代码的很多部分中,我有以下代码架构:
def isInUseByOutgoingRegistrations(self ,archivefolder):
例如self.findActiveOutgoingRegistrationInstances():
if instance.forbidToClose(archivefolder):
return True
返回False
在为这类问题设计我自己的解决方案之前,我想知道是否有一个解决这个问题的常见解决方案。我正在寻找一个
python2.3解决方案。
问候
Marco
-
Marco Bizzarri
http:/ /notenotturne.blogspot.com/
http://iliveinpisa.blogspot。 com /
Hi all.
In many parts of my code I''ve the following schema of code:
def isInUseByOutgoingRegistrations(self, archivefolder):
for instance in self.findActiveOutgoingRegistrationInstances():
if instance.forbidToClose(archivefolder):
return True
return False
Before devising my own solution for this kind of problem, I wonder if
there is a common solution for the problem. I''m looking for a
python2.3 solution.
Regards
Marco
--
Marco Bizzarri
http://notenotturne.blogspot.com/
http://iliveinpisa.blogspot.com/
推荐答案
Marco Bizzarri schrieb:
Marco Bizzarri schrieb:
大家好。
在我的代码的很多部分中,我有以下代码架构:
def isInUseByOutgoingRegistrations(self,archivefolder):
例如在self.findActiveOutgoingRegistrationInstances()中:
如果instance.forbidToClose(archivefolder):
返回True
返回错误
在为这类问题设计我自己的解决方案之前,我想知道是否
那里是这个问题的常见解决方案。我正在寻找一个
python2.3解决方案。
Hi all.
In many parts of my code I''ve the following schema of code:
def isInUseByOutgoingRegistrations(self, archivefolder):
for instance in self.findActiveOutgoingRegistrationInstances():
if instance.forbidToClose(archivefolder):
return True
return False
Before devising my own solution for this kind of problem, I wonder if
there is a common solution for the problem. I''m looking for a
python2.3 solution.
if bs(instance.forbitToClose(archivefolder)例如
self.findActiveOutgoingRegistrationInstances())
你还应该考虑使用PEP8风格的命名。
Diez
if any(instance.forbitToClose(archivefolder) for instance in
self.findActiveOutgoingRegistrationInstances())
You should also consider using PEP8 style naming.
Diez
2008年9月12日星期五下午4:09, Diez B. Roggisch< de *** @ nospam.web.dewrote:
On Fri, Sep 12, 2008 at 4:09 PM, Diez B. Roggisch <de***@nospam.web.dewrote:
Marco Bizzarri schrieb:
Marco Bizzarri schrieb:
>>
大家好。
在我的代码的很多部分中,我有以下代码架构:
def isInUseByOutgoingRegistrations(self ,archivefolder):
例如在self.findActiveOutgoingRegistrationInstances():
如果instance.forbidToClose(archivefolder):
返回True
返回False
之前为这类问题设计我自己的解决方案,我想知道是否有一个共同的问题解决方案。我正在寻找一个
python2.3解决方案。
>>
Hi all.
In many parts of my code I''ve the following schema of code:
def isInUseByOutgoingRegistrations(self, archivefolder):
for instance in self.findActiveOutgoingRegistrationInstances():
if instance.forbidToClose(archivefolder):
return True
return False
Before devising my own solution for this kind of problem, I wonder if
there is a common solution for the problem. I''m looking for a
python2.3 solution.
如果有的话(例如,在
中的instance.forbitToClose(archivefolder)self.findActiveOutgoingRegistrationInstances())
if any(instance.forbitToClose(archivefolder) for instance in
self.findActiveOutgoingRegistrationInstances())
你能澄清我在哪里可以找到任何吗?在我看来,我找不到它......
Can you clarify where I can find "any"? It seems to me I''m unable to find it...
你还应该考虑使用PEP8风格的命名。
You should also consider using PEP8 style naming.
我知道有人会这样对我说:-)。
我这样做......慢慢来。我正在尝试修复命名约定,因为我必须处理我的代码...
I knew that someone would have said that to me :-).
I''m doing that... slowly. I''m trying to fix naming conventions as I
had to work on my code...
Diez
-
http://mail.python .org / mailman / listinfo / python-list
-
Marco Bizzarri
http://notenotturne.blogspot.com/
http://iliveinpisa.blogspot.com/
> if any(instance.forbitToClose(archivefolder),例如
>if any(instance.forbitToClose(archivefolder) for instance in
> self.findActiveOutgoingRegistrationInstances())
>self.findActiveOutgoingRegistrationInstances())
你能澄清我在哪里可以找到任何吗?在我看来,我找不到它...
Can you clarify where I can find "any"? It seems to me I''m unable to find it...
它是python2.5的一部分。
如果你没有那个,你可以自己编写并将其填入
__builtins__:
It''s part of python2.5.
If you don''t have that, you can write it your own and stuff it into
__builtins__:
>> def any(iterable):
>>def any(iterable):
.. .. for iterable中的项目:
.... if item:
.... return True
.... return False
....
.... __ builtin __。any = any
您可能还想添加所有,同伴的伴侣:
.... for item in iterable:
.... if item:
.... return True
.... return False
....
.... __builtins__.any = any
You might also want to add all, the companion of any:
>> def all(iterable):
>>def all(iterable):
.... for iterable中的项目:
....如果不是项目:
....返回False
....返回True
....
Diez
.... for item in iterable:
.... if not item:
.... return False
.... return True
....
Diez
这篇关于检查集合的布尔值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!