系统:Ubuntu 15.04
按步骤来:
1.确认安装python,我的版本为2.7.9
2.若要使用mysql,需安装MySQL-python包,安装之前确认已经安装了setuptools
python setup.py build时若出现错误,基本上安装下python-dev和libmysqld-dev即可
3.
贴个代码,可访问mysql、解析json、so库调用
-
#!/usr/bin/python
-
# -*- coding: utf-8 -*-
-
-
import web
-
from ctypes import *
-
import os
-
import urllib
-
import simplejson as json
-
-
#web.config.debug = True
-
-
render = web.template.render("templates/")
-
-
db = web.database(dbn='mysql',user='root',pw='123456',db='test')
-
-
urls = (
-
'/', 'index',
-
'/add','add',
-
'/urlcatch','urlcatch',
-
'/json','json',
-
)
-
-
app = web.application(urls, globals())
-
-
class index:
-
def GET(self):
-
todos = db.select('list')
-
libtest = cdll.LoadLibrary(os.getcwd() + '/libtest.so')
-
print libtest.add(10,10)
-
return render.index1(todos)
-
-
class add:
-
def POST(self):
-
i = web.input()
-
n = db.insert('list',username=i.username)
-
web.seeother('/')
-
-
class urlcatch:
-
def GET(self):
-
url = ''
-
page = urllib.urlopen(url)
-
data = page.read()
-
return data
-
-
class json:
-
def GET(self):
-
json_obj = '[{"name":"鸟巢","point":{"lat":"39.990","lng":"116.397"},"desc":"奥运会主场 地"},{"name":"北
-
大乒乓球馆","point":{"lat":"39.988","lng":"116.315"},"desc":"乒乓 球比赛场地"},{"name":"北京工人体育场","point": {"lat":"39.930","lng":"116.446"},"desc":"足球比赛场地"}]'
-
py_objs = json.loads(json_obj)
-
print len(py_objs)
-
for py_obj in py_objs:
-
print py_obj["name"]
-
print py_obj["point"]["lat"]+','+py_obj["point"]["lng"]
-
print py_obj["desc"]
-
-
if __name__ == "__main__":
-
app.run()
阅读(1607) | 评论(0) | 转发(0) |