python print 打印unicode string的时候 去掉u' remove u'

1. 对list型的 用join 方法,是可以的实现的
myUlist  = [ u'AB' u'AB' u'AB' u'AB' ]
print  myUlist

print ", ".join(myUlist)

[u'AB', u'AB', u'AB', u'AB']
AB, AB, AB, AB

2. 对json data 型的数据,用json.dump 方法, 是可以的实现的

read_json is {u'enableCwp': False, u'vendorId': u'', u'radioBand': u'DUAL', u'authenticationProtocol': u'PAP', u'userProfileAssignmentRules': []}

read_json = load_json_file(r'D:\psk-demo.json')
read_json_str = str(read_json).decode('utf-8')
print "read_json is %s end" % read_json_str
#print str({u"foo": "bar"})

turns = json.dumps(read_json)
print "turns is: %s " %turns

read_json is {u'enableCwp': False, u'vendorId': u'', u'radioBand': u'DUAL', u'authenticationProtocol': u'PAP', u'userProfileAssignmentRules': []}

turns is: {"enableCwp": false, "vendorId": "", "radioBand": "DUAL", "authenticationProtocol": "PAP", "userProfileAssignmentRules": []}


3. 对于单个string 串,可以用replace

def remove_uni(s):
    """remove the leading unicode designator from a string"""
    s2 = ''
    if s.startswith("u'"):
        s2 = s.replace("u'", "'", 1)
    elif s.startswith('u"'):
        s2 = s.replace('u"', '"', 1)
    return s2
s = 'u"you\'re my favorite string"'
sa = "u'mystring'"
print remove_uni(s)  # "you're my favorite string"
print remove_uni(sa) # 'mystring'

ref:


  • 3
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

youcharming

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值