I have constructed my own class User which has the property userID. I override the __repr__ so that it’s the userID string.
In another class I have an array self.users = [] with a couple User instances. For testing purposes I gave them user ID’s 1 and 2. I use:
'[%s]' % ','.join(map(str, self.users))
To print the contents of the array, producing:
[1,2]
I’m trying to make an if statement along the lines of:
if "1" in self.users:
print "True"
Above is a simple representation of what I’m trying to achieve. I have tried many approaches and I can’t get the program to print true. Does anyone know how to do this?
Do you want:
probably better is:
if I’m reading your post correctly.
Finally, depending on the API for
User, you could use theIDin an equality test:Now you can use
__contains__(in) on your list as you were trying to do initially: