Python菜鸟,我不知道为什么会给出SyntaxError:语法无效

时间:2019-03-07 20:45:42

标签: python syntax-error

如标题所示,我在

处出现语法错误
temp_string = lines[1][equals_pos+2:] from datetime import date

我不确定如何修复它,否则怎么了?

def read_temp():
    lines = read_temp_raw()
    while lines[0].strip()[-3:] != 'YES':
        time.sleep(0.2)
        lines = read_temp_raw()
    equals_pos = lines[1].find('t=')
    if equals_pos != -1:
        temp_string = lines[1][equals_pos+2:] from datetime import date
from apscheduler.scheduler import Scheduler
        temp_c = float(temp_string) / 1000.0
        temp_f = temp_c * 9.0 / 5.0 + 32.0
        return temp_f

1 个答案:

答案 0 :(得分:0)

import语句应放在单独的行

from datetime import date
from apscheduler.scheduler import Scheduler
def read_temp():
    lines = read_temp_raw()
    while lines[0].strip()[-3:] != 'YES':
        time.sleep(0.2)
        lines = read_temp_raw()
    equals_pos = lines[1].find('t=')
    if equals_pos != -1:
        temp_string = lines[1][equals_pos+2:]
        temp_c = float(temp_string) / 1000.0
        temp_f = temp_c * 9.0 / 5.0 + 32.0
        return temp_f