Re: Converting bytes to unicode that works both in python2 and 3

2015-05-19 Thread Vernon D. Cole
if sys.version_info >= (3,0): def str2bytes(sval): return sval.encode("latin1") unicode = str else: def str2bytes(sval): if isinstance(sval, str): return sval return sval.encode("latin1") This is what I use to solve the opposite problem. It should gi

Converting bytes to unicode that works both in python2 and 3

2015-05-19 Thread Hanne Moa
I got to start a new django 1.8-project in python 3.4 for once, and happily coded away. Turns out, the PaaS it needs to run on has a broken python 3.4, so... my code now needs to work in 2.7.8. Everything works in both versions except I need to read from an uploaded file, bot in the web and from t