I am learning about the Twitter API using Python 2.7.x. I\'ve saved a number of random tweets and I am trying to process them. Each tweet is converted to a dictionary with j
Python 2 handles translation between str
and unicode
keys transparently for you, provided the text can be encoded to ASCII:
>>> d = {u'text': u'Foo'}
>>> d.keys()
[u'text']
>>> 'text' in d
True
>>> u'text' in d
True
>>> d['text']
u'Foo'
>>> d[u'text']
u'Foo'
This means that if you get a KeyError
for tweet['text']
, then that dictionary has no such key.
Python 2.7.8 (default, Jun 30 2014, 16:03:49) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> d = {u'text': u'Foo'}
>>> print "d:{text}".format(**d)
d:Foo