That code alone does not give you the error. For example:
~ $ python3.2
>>> variable = str(21)
Somewhere in your code, you have defined the str = something else, hiding the built-in definition of str. So you need to remove it, then your code will work fine.
Want to gain end-to-end skills in Data Science with Python? Enroll today in this Data Science with Python Course and be a master in it