【发布时间】:2016-05-16 17:36:38
【问题描述】:
x.split() 下面的结果是我想要的,因为结果中没有 unicode。
server:~ brian$ python
Python 2.7.1 (r271:86832, Jul 31 2011, 19:30:53)
[GCC 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2335.15.00)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> x = 'M Y'
>>> x.split()
['M', 'Y']
但在我使用db.get 的应用程序中,choices 的结果是[u'M', u'Y'],而不是'choices' = 'M Y'。
def post(self, blog_id):
blog = db.get(db.Key.from_path('Blogs', blog_id))
n = Reminders(parent=blog, purpose=self.request.get('purpose'),
choices=self.request.get('choices').split())
n.put()
我怎样才能得到我想要的结果?
这个问题与另一个问题不同,因为 google-app-engine 或 python2.7 似乎在被拆分的序列的每个元素周围强制使用 u''。我也尝试过使用.encode('ascii','ignore'),但无济于事。
【问题讨论】:
-
这对您的程序有何影响?...因为我认为建议处理 unicode 字符串,并且由于您正在处理 Python2.7,因此很自然会得到
u'M'和u'Y'作为输出...因为它们在您的db对象中被视为 unicode 字符串。 -
在我看来您正在使用 GAE DB?...我错了吗?
-
它会影响我的程序,因为我想将结果作为参数/参数之一包含到 javascript 函数中。 js 函数因该参数而窒息。我一直fiddling with it here 如果你去那里,试着双击“M”。然后将函数的输入更改为包含 u'。
标签: python