1

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

anthr
  • 1,026
  • 4
  • 17
  • 34

1 Answers1

1

You should use == instead of is.

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

Related Question

Community
  • 1
  • 1
Mark Byers
  • 811,555
  • 193
  • 1,581
  • 1,452