To use unicode or not in web development project using flask and sqlalchemy

ε祈祈猫儿з 提交于 2019-12-11 01:16:38

问题


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:


  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.



来源:https://stackoverflow.com/questions/7860643/to-use-unicode-or-not-in-web-development-project-using-flask-and-sqlalchemy

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!