forked from smilejay/python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstring2dict.py
More file actions
34 lines (28 loc) · 766 Bytes
/
string2dict.py
File metadata and controls
34 lines (28 loc) · 766 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
'''
Created on Oct 14, 2014
@author: Jay <smile665@gmail.com>
'''
import MySQLdb
import ast
import json
def my_run():
try:
s = '{"host":"10.1.77.20", "port":3306, "user":"abc",\
"passwd":"123", "db":"mydb", "connect_timeout":10}'
d = ast.literal_eval(s)
print type(d)
print d
d1 = eval(s)
print type(d1)
print d1
d2 = json.loads(s)
print type(d2)
print d2
MySQLdb.Connect(host=d['host'], port=d['port'], user=d['user'],
passwd=d['passwd'], db=d['db'],
connect_timeout=d['connect_timeout'])
print 'right'
except Exception, e:
print 'wrong %s' % e
if __name__ == '__main__':
my_run()