小编Pho*_*tic的帖子

无法将度数符号输入raw_input

我的代码中的问题看起来像这样:

#!/usr/bin/python
# -*- coding: UTF-8 -*-

deg = u'°'
print deg
print '40%s N, 100%s W' % (deg, deg)
codelim = raw_input('40%s N, 100%s W)? ' % (deg, deg))
Run Code Online (Sandbox Code Playgroud)

我正在尝试为纬度/经度字符串中的定界符生成raw_input提示,提示中应包含此类字符串的示例。print deg并且print '40%s N, 100%s W' % (deg, deg)都可以正常工作-它们分别返回“°”和“ 40°N,100°W”-但该raw_input步骤每次都失败。我得到的错误如下:

Traceback (most recent call last):
  File "C:\Users\[rest of the path]\scratch.py", line 5, in  <module>
    x = raw_input(' %s W")? ' % (deg))
UnicodeEncodeError: 'ascii' codec can't encode character u'\xb0' in position 1:
ordinal not …
Run Code Online (Sandbox Code Playgroud)

python character-encoding python-2.7 python-unicode

3
推荐指数
1
解决办法
1622
查看次数