Вопрос

I am working on a web development project using flask and sqlalchemy orm. My post is related to use of unicode in developing this app. What I have understood till now about unicode :

  1. If I want my webapp to handle data in languages other than English I need to use unicode data type for my variables. Because string variables can't handle unicode data.

  2. I use some database which stores unicode data or take responsibility to convert unicode to raw while saving and vice versa while retrieving. Sqlalchemy gives me option to set automatic conversion both ways, so that I dont have to worry about them.

  3. I am using python2.7 so I have to be aware of processing unicode data properly. Normal string operations on unicode data maybe buggy.

Correct me if any of the above assumption is wrong.

Now my doubts or questions :

  1. If I dont use unicodes now then will I have some problems if I or flask people decide to port to python3?

  2. I dont want to hassle with the thought of my webapp catering to different languages right now. I just want to concentrate on first creating the app. Can I do that later without using unicode right now?

  3. If I use unicode now then how it affects my code. Do I replace every string input and output with unicode or what?

  4. Conversion of unicode when saving to database, Can it be source of performance problems?

Basically I am asking whether to use unicode or not with explaining my needs and requirement out of the project.

Это было полезно?

Решение

  1. No, but make sure you separate binary data from text data. That makes it easier to port.

  2. It's easier to use Unicode from the start, but of course you can postpone it. But it's really not very difficult.

  3. You replace everything that should be text data with Unicode, yes.

  4. Only of you make loads of conversions of really massive amounts of text.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top