简体   繁体   English

Django Python在queryset中转换unicode

[英]django python convert unicode in queryset

How convert u'[<Car: { surname :yass name : zazadz } >] in [<Car: { surname :yass name : zazadz } >] . 如何u'[<Car: { surname :yass name : zazadz } >]中转换u'[<Car: { surname :yass name : zazadz } >] [<Car: { surname :yass name : zazadz } >]

So how convert unicode in django.db.models.query.QuerySet ? 那么如何在django.db.models.query.QuerySet转换unicode?

This is the function I wrote to convert unicode into string which i then process according to my need. 这是我编写的用于将unicode转换为字符串,然后根据需要进行处理的函数。 _in_unicode is the parameter passed to this function, which takes an input of type unicode. _in_unicode是传递给此函数的参数,它接受unicode类型的输入。

def unicode_to_string(_in_unicode):
return unicodedata.normalize('NFKD', _in_unicode).encode('ascii', 'ignore')

You will have to write a parser to process that string and then convert it into proper format for data processing. 您将必须编写一个解析器来处理该字符串,然后将其转换为正确的格式以进行数据处理。

PS: If you are downvoting, please add comment for the reason. PS:如果您不赞成投票,请添加评论以说明原因。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM