Skip to content

Instantly share code, notes, and snippets.

@include
Created January 22, 2014 15:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save include/8561058 to your computer and use it in GitHub Desktop.
Save include/8561058 to your computer and use it in GitHub Desktop.
Playing with unicode on Python 2.7
# -*- coding: utf-8 -*-
from __future__ import print_function, unicode_literals
from pprint import pprint
import json
st = u"lol"
lt = [["foo", 1],["bar", 2]]
foo = {"keys": "hosts",
"bar": True,
"values": lt,}
bar = json.dumps(foo)
enc_st = st.encode('utf-8')
dec_st = st.decode('utf-8')
print("lt: {l}".format(l=lt))
print("foo: {f}".format(f=foo))
print("bar: {b}".format(b=bar))
print("raw_st: {st}".format(st=st))
print("enc_st: {es}".format(es=enc_st))
print("dec_st: {ds}".format(ds=dec_st))
print("---")
pprint(lt)
pprint(foo)
pprint(bar)
pprint(st)
pprint(enc_st)
pprint(dec_st)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment