Skip to content

Instantly share code, notes, and snippets.

@scott-w
Created March 18, 2017 13:12
Show Gist options
  • Save scott-w/325fc5d996edbb22fb8da09dd8f1b3d4 to your computer and use it in GitHub Desktop.
Save scott-w/325fc5d996edbb22fb8da09dd8f1b3d4 to your computer and use it in GitHub Desktop.
from __future__ import absolute_import, print_function, unicode_literals
from six import string_types, text_type, binary_type
## Python 2 only
some_value = 20
value_as_string = unicode(some_value)
value_as_bytes = str(some_value)
isinstance(value_as_string, basestring)
## Using six, this becomes
some_value = 20
value_as_string = text_type(some_value)
value_as_bytes = binary_type(some_value)
isinstance(value_as_string, string_types)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment