Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference in python between basestring and types.StringType?

Tags:

python

What's the difference between:

isinstance(foo, types.StringType)

and

isinstance(foo, basestring)

?

like image 272
10 revs, 7 users 53% Avatar asked Oct 27 '09 19:10

10 revs, 7 users 53%


1 Answers

For Python2: basestring is the base class for both str and unicode, while types.StringType is str. If you want to check if something is a string, use basestring. If you want to check if something is a bytestring, use str and forget about types.

like image 94
Lukáš Lalinský Avatar answered Sep 30 '22 16:09

Lukáš Lalinský