tags:

views:

27

answers:

1

Hi there-

I have a list of objects which I built with a class, and one of the properties of this class is the variable "tag". (below called tagList)

I am trying to match this variable from a record that is bought in using MySQLdb. (below called record)

I can output both to the screen, and see them identically by eye, although cannot get any if statement to match them.

I have tried several approaches, such as:

if str(tagList[i].tag)[2:6] is record[2]:

if str(tagList[i].tag)[2:6] is str(record[2]):

and other similar things. ([2:6] just to remove the [' '] from the list element. Printing these variables to the screen does show they are in the correct format, and I must be doing something stupid!

Still new to both Python and MySQL so would appreciate any advice!

Thanks

+1  A: 

You should use == instead of is.

>>> 'abcdefgh'[2:6] is 'cdef'
False
>>> 'abcdefgh'[2:6] == 'cdef'
True

Related Question

Mark Byers
How did I make that mistake? Eugh. Sorry to waste your time!Thanks a lot.
anthr
You're welcome.
Mark Byers