这是我的python模块:
#!/usr/bin/python
import rpy2.robjects as robjects
import MySQLdb as mdb
import json
import rpy2.robjects.vectors as ro
r= robjects.r
class Deviation:
def __init__(self):
print("Standard Deviation")
def s_deviation(self):
con = mdb.connect('localhost', 'root', 'devil', 'data')
cursor = con.cursor()
cursor.execute("SELECT * FROM traffic")
rows = cursor.fetchall()
rows = list(rows)
a = [x[1] for x in rows]
result = ro.IntVector(a)
a = r.sd(result)
print a
def deviation():
dev = Deviation()
deviation = dev.s_deviation()
调用此模块的函数 deviation() 将结果作为 R 向量返回。如何使它返回 Json 对象的结果?谢谢!