python3编译器运行无措,终端运行即出错,小白求教大神

weixin_40101242 2018-08-30 09:12:07
代码为:
import json
import pymysql
def get_data():
with open('/var/www/html/aqi1.json', 'r') as f:
pm_text = json.load(f) # 解析每一行数据
return pm_text
def data_insert(pm_text):
db = pymysql.connect("localhost", "root", "trafficlab507-1", "sensordb ")
cursor = db.cursor()
value_pm = ((pm_text['aqi1']['pm10'], pm_text['aqi1']['pm25'], pm_text['aqi1']['time']))
insert_pm = "insert into pmdb(pm10,pm25,recordtime) values (%s,%s,%s)"
cursor = db.cursor()
cursor.execute(insert_pm, value_pm)
db.commit()
cursor.close()
报错内容为:
./qq.py:行3: 未预期的符号 `(' 附近有语法错误
./qq.py:行3: `def get_data():'
...全文
342 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
你是windows?下运行的 with open('/var/www/html/aqi1.json', 'r') as f: 这里 你可以尝试写成// 或者\ 试试 还有就是上面说的对齐问题
weixin_40101242 2018-08-30
  • 打赏
  • 举报
回复
引用 2 楼 hbu_pig 的回复:
感觉是空格没对齐

对齐就报错了,我在python3里写的,写好运行无措,可是终端运行就出错。
欢乐的小猪 2018-08-30
  • 打赏
  • 举报
回复
感觉是空格没对齐
weixin_40101242 2018-08-30
  • 打赏
  • 举报
回复
顶一下,谢谢各位大神了。

37,721

社区成员

发帖
与我相关
我的任务
社区描述
JavaScript,VBScript,AngleScript,ActionScript,Shell,Perl,Ruby,Lua,Tcl,Scala,MaxScript 等脚本语言交流。
社区管理员
  • 脚本语言(Perl/Python)社区
  • IT.BOB
加入社区
  • 近7日
  • 近30日
  • 至今

试试用AI创作助手写篇文章吧