python 字符串操作通用异常处理


#!/bin/env python

-- coding: utf-8 --

import json

a={}
a['name'] = "test"
a['age'] = '18'
b="fdsfdsfdsfd"
a1=[]
a1.append(a)

try:
str1=json.dumps(a1)
except Exception as e:
print "convert a failed"
else:
print "convert a success:%s" % str1

b1=[]
b1.append(b)
print b1

try:
str1=json.dumps(b1)
except Exception as e:
print "convert b failed"
else:
print "convert b success:%s" % str1

This entry was posted in DEVOPS. Bookmark the permalink. Follow any comments here with the RSS feed for this post. Both comments and trackbacks are currently closed.