[Zope] Help using list within python method
Passin, Tom
tpassin@mitretek.org
Fri, 21 Mar 2003 16:10:37 -0500
[Michael Long]
>=20
> I have a method that is returning an error that I have not=20
> been able to
> resolve. I have tried to duplicate the error in python to no=20
> avail. I am
> sure the solution is very simple I just don't see it.
>=20
>=20
> Here is the method:
>=20
> 172 def listEntriesByGroup(self, groups=3D["All"]):
> 173 "Method to list Entries"
> 174 ret=3D[]
> 175 if type(groups) !=3D ListType:
> 176 EntryIDs =3D [groups]
> 177 if groups =3D=3D "All":
> 178 for entry in self.Entries.values():
> 179 ret.append(entry)
> 180 else:
> 181 for entry in self.Entries.values():
> 182 if entry.Group in groups:
> 183 ret.append(entry)
> 184 return ret
>=20
> The traceback is:
[snip]=20
> Module Products.dlAddressBook.AddressBook, line 182, in=20
> listEntriesByGroup
> TypeError: 'in <string>' requires character as left operand
Your test if groups =3D=3D "All" must always fail if no argument is =
passed
in(since the default argument is a list, not a string) or if the
argument is a string. If so, you will always execute the "else" at line
180, where the traceback says the error is..
Now if groups is really a string and entry.Group is not a string, that
would cause the error. So you had best check to see what type of
critter you are using there.
Are you sure you did not mean to make use of EntryID somewhere?
Cheers,
Tom P