python - Python noob,我不知道它为什么给出 SyntaxError: Invalid syntax
问题描述
正如标题所说,我在
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
解决方案
导入语句应该在单独的行
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
推荐阅读
- .net - 加载 EML 文件时未获取电子邮件的所有属性
- python - Azure Python SDK:BlobServiceClient 与 BlobClient?
- flutter - 如何在颤动中为滑块中的拇指图标赋予矩形形状?
- python - IndexError:列表索引超出范围。对于 Stitch API,当我使用 python 做 API 时,对于一些输入,我得到输出,只有最后一行有索引错误
- android - Prism.Forms DI:如何避免多个单例实例?
- java - 调用 api 时获取 {"status":100,"errormsg":"Failed to parse text in form param"}
- python - 如何在 python 中找到 y 的最小值和最大值并在它们之间绘制边界?
- php - 如何将产品和类别 ID 附加到 woocommerce 中所有产品的 URL 末尾的查询字符串
- swift - 带有 http 状态码的 swift ui http 请求
- javascript - 如何删除特定的多个字符串然后保留另一个?