简体   繁体   English

python代码缩进不一致

[英]python code inconsistent indentation

I have been working on a project which is getting the data from a temperature sensor that is connected to the arduino. 我一直在进行一个项目,该项目从与arduino连接的温度传感器获取数据。 I need to get that data to my raspberry pi and display it online. 我需要将该数据保存到我的树莓派中并在线显示。 so I wrote python code that should get the data and put it in a sqlite database file. 所以我写了应该获取数据并将其放入sqlite数据库文件的python代码。 I try this code using python idle2 and idle 3 I cannot get it working. 我尝试使用python idle2和idle 3编写此代码,但无法正常工作。 would be cause pf i have both python 2 and 3 installed to my rasbian? 会导致pf我同时将python 2和3安装到我的rasbian吗? or there is a problem with the code? 还是代码有问题?

here is the code; 这是代码;

#!/ussr/bin/python
# -*- coding: utf-8 -*-


import serial
import datetime
import sqlite3 as lite
import sys
import time

ser = serial.Serial('/dev/ttyAMA0', 9600, timeout=1)
ser.open()

count = 0

con = lite.connect('data.db')

try:
  while 1:
    indata = ser.readline()
    current_time = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
    count = count + 1

    print indata + current_time
    print count

    with con:
      cur = con.cursor()
      cur.execute("INSERT INTO Temperatures VALUES( ?, ?, ? )", (count, current_time, indata))

      if count > 100:
        cur.execute("DELETE FROM Temperatures")
        count = 0
Interrupt:
  ser.close()

尝试将“中断:”更改为“例外:”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM