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 the commandline. In the management command I
can do:

import io
with io.open(fieldname, 'rt', encoding='UTF-8') as F: do_stuff(F)

... and it works in both 2.7.8 and 3.4.x.

But a FileField in Python 3 reads stuff as bytes. So in the form, I need to
check whether the chunk of data I get is bytes, and if it is, convert it to
unicode from 'UTF-8'.

How to do that? It'll probably involve six in some way but the docs for
six, and django's "how to have things run on both python 2 and 3"-docs,
could be better.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CACQ%3DrrfKyM0O%3DamjOX2j9LTrvZQHS_3RJ8eo_Hyn9Js1ML9YBQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to