with open("data.txt") as f:
filecontents = simplejson.load(f)
is indeed reloading the data exactly as you specify. What may be confusing you is that all strings in JSON are always Unicode -- JSON (like Javascript) doesn't have a "byte string" data type distinct from "unicode".
Edit I don't have the old simplejson
around any more (since its current version has become part of the standard Python library as json
), but here's how it works (making json
masquerade as simplejson
in the hope of avoiding confusing you!-)...:
>>> import json
>>> simplejson = json
>>> f = open("data.txt","w")
>>> l = ["a","b","c"]
>>> simplejson.dump(l,f)
>>> f.close()
>>> with open("data.txt") as f: fc = simplejson.load(f)
...
>>> fc
[u'a', u'b', u'c']
>>> fc.append("d")
>>> fc
[u'a', u'b', u'c', 'd']
>>>
If this exact code (net of the first two lines if what you do instead is import simplejson
of course;-) doesn't match what you observe, you've found a bug, so it's crucial to report what versions of Python and simplejson
you're using and exactly what error you get, complete with traceback (edit your Q to add this -- obviously crucial -- info!).