我能够成功运行代码,但希望能够永久循环它。它是我第一次尝试Python,任何帮助,将不胜感激。我所做的是在代码的顶部放置了“While True:”,但我一直收到“Sorry Indentation Error:expected a indenting block line 3”的错误,但没有它,它工作正常,但只运行一次。所以我的问题是我怎样才能循环而不会出现错误?为什么我不能在第一行写上“While True:”?Noob查询Python(树莓派)
While True:
# Open the file that we viewed earlier so that python can see what is in it. Replace the serial number as before.
tfile = open("/sys/bus/w1/devices/10-000802824e58/w1_slave")
# Read all of the text in the file.
text = tfile.read()
# Close the file now that the text has been read.
tfile.close()
# Split the text with new lines (\n) and select the second line.
secondline = text.split("\n")[1]
# Split the line into words, referring to the spaces, and select the 10th word (counting from 0).
temperaturedata = secondline.split(" ")[9]
# The first two characters are "t=", so get rid of those and convert the temperature from a string to a number.
temperature = float(temperaturedata[2:])
# Put the decimal point in the right place and display it.
temperature = temperature/1000
import time
print temperature
time.sleep(5)
好像你需要读一个Python的教程,它可以解释语法的基础知识这个样子。在不知道缩进所起作用的情况下,用Python进行编程是不可能的。 – Barmar
''while'的'w'应该是小写 –