我试图找到一种简单快速的方法来计算列表中符合条件的对象数量.例如
class Person:
def __init__(self, Name, Age, Gender):
self.Name = Name
self.Age = Age
self.Gender = Gender
# List of People
PeopleList = [Person("Joan", 15, "F"),
Person("Henry", 18, "M"),
Person("Marg", 21, "F")]
Run Code Online (Sandbox Code Playgroud)
现在,计算此列表中与基于其属性的参数匹配的对象数量的最简单函数是什么?例如,为Person.Gender =="F"或Person.Age <20返回2.
我试过了pip install --upgrade sqlalchemy,python2.7 setup.py install在删除site-packages中的sqlalchemy文件夹之后,我试过了pip install sqlalchemy.它们都给出了"RuntimeError:cmp中超出了最大递归深度".
File "C:\Python27\lib\ntpath.py", line 200, in splitext
return genericpath._splitext(p, sep, altsep, extsep)
File "C:\Python27\lib\genericpath.py", line 102, in _splitext
sepIndex = max(sepIndex, altsepIndex)
RuntimeError: maximum recursion depth exceeded in cmp
Run Code Online (Sandbox Code Playgroud)
我还试图为v0.9运行setup.py并获得相同的结果.尝试在setup.py中添加一行以将最大递归设置为10000并且python崩溃.
编辑:回溯是一个很长的重复:
File "c:\python27\lib\site-packages\distribute-0.6.28-py2.7.egg\setuptools\dist.py", line 225, in __init__
_Distribution.__init__(self,attrs)
File "c:\python27\lib\distutils\dist.py", line 287, in __init__
self.finalize_options()
File "c:\python27\lib\site-packages\distribute-0.6.28-py2.7.egg\setuptools\dist.py", line 257, in finalize_options
ep.require(installer=self.fetch_build_egg)
File "c:\python27\lib\site-packages\distribute-0.6.28-py2.7.egg\pkg_resources.py", line 2029, in require
working_set.resolve(self.dist.requires(self.extras),env,installer))
File "c:\python27\lib\site-packages\distribute-0.6.28-py2.7.egg\pkg_resources.py", line 580, in resolve
dist = …Run Code Online (Sandbox Code Playgroud) python ×2
attributes ×1
count ×1
list ×1
object ×1
pip ×1
python-2.7 ×1
recursion ×1
sqlalchemy ×1