【问题标题】:Hindi Font - python 2.7 urllib2 and json印地语字体 - python 2.7 urllib2 和 json
【发布时间】:2016-01-27 06:10:55
【问题描述】:
>>> url = https://graph.facebook.com/508246595873195/posts?limit=1&access_token="token"
>>> import json
>>> import urllib2
>>> response = urllib2.urlopen(utl)
>>> data = json.load(response)
>>> for i in data['data'][0]['likes']['data']:
        print i

此代码片段来自http://facebook.com (page=Unilever) 的帖子点赞

{likes} 数据如下:

{u'id': u'1678630835690215', u'name': u'Binay Barman'}
{u'id': u'770653513044206', u'name': u'\u0926\u0947\u0935 \u092a\u093e\u0930\u0940\u0915'} 

这个u'\u0926\u0947\u0935 \u092a\u093e\u0930\u0940\u0915' 在正常的印地语文本中是“देव पारीक”

我想知道如何用印地语而不是 unicode 打印这个!!!

【问题讨论】:

  • text.encode('utf-8') - 编码为 utf-8 或任何你使用的。
  • 啊!让打印引擎完成工作print u'\u0926\u0947\u0935 \u092a\u093e\u0930\u0940\u0915'.encode('utf_8_sig')
  • @SIslam,这个结果 = देव पारीक

标签: python json python-2.7


【解决方案1】:

例如:

>>> a = u'\u0926\u0947\u0935 \u092a\u093e\u0930\u0940\u0915'
>>> a.encode('utf-8')

结果:

'\xe0\xa4\xa6\xe0\xa5\x87\xe0\xa4\xb5\xe0\xa4\xaa\xe0\xa4\xbe\xe0\xa4\xb0\xe0\xa5\x80\xe0\xa4\x95'

我想要这个印地文字体

【讨论】:

  • 试试print( a.encode('utf-8') ) - 如果你不使用print 然后控制台使用repr() 打印它 - print( repr( a.encode('utf-8') ) )
  • @furas 打印结果(repr( a.encode('utf-8') ) )是 '\xe0\xa4\xa6\xe0\xa5\x87\xe0\xa4\xb5 \xe0 \xa4\xaa\xe0\xa4\xbe\xe0\xa4\xb0\xe0\xa5\x80\xe0\xa4\x95'
  • print(a.encode('utf-8')) 的结果(没有repr)?当您不直接使用print() 时,控制台/shell 使用repr()
  • @furas,结果是 देव पारीक
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-04-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-06-20
  • 2016-06-17
相关资源
最近更新 更多