我一直在做一段时间的自动化百叶窗/窗帘项目现在一切正常,但我想添加百叶窗在早上逐渐打开的功能。我正在从配置文件中读取我的值,并将值转换为可正常工作的字符串,但由于某些原因无法分割该值。我已经尝试了很多方法来做到这一点,但我似乎遇到错误,如:SyntaxError:不能分配给运算符和TypeError:不能连接'str'和'int'对象。有没有人有任何想法,我如何分割一个Python字符串,然后使用该字符串作为睡眠值?在python中划分字符串2.7
我是相当新的编程(我13)
from ConfigParser import SafeConfigParser
config = SafeConfigParser()
config.read('/home/pi/config.conf') #read config file
openTime = config.get('blinds', 'open time(secs)') # -> "openTime"
print 'Overall open time ' + openTime + ' seconds'
## code to divide openTime by 5 and print the value
print 'gradual open time' + DividedOpenTime + ' seconds'
## code to repeat in a loop 5 times with a sleep of the value of
## DividedOpenTime
编辑1
嗨,我再次做了什么我被告知要添加到代码,它解决了问题的分工和睡眠时间,但由于某些原因,我无法打印值。第11行和第15行都有以下错误:
Traceback (most recent call last):
File "test.py", line 11, in <module>
print 'gradual open time' + divOpenTime + ' this will repeat 5 times'
TypeError: cannot concatenate 'str' and 'float' objects
有谁知道我该如何解决此问题?
from ConfigParser import SafeConfigParser
config = SafeConfigParser()
import time
config.read('/home/pi/config.conf') #read config file
openTime = config.get('blinds', 'open time(secs)') # -> "openTime"
print 'Overall open time ' + openTime + ' seconds'
divOpenTime = float(openTime)/5 #working (:
loop = 0
print 'gradual open time' + divOpenTime + ' this will repeat 5 times'
for x in range(0, 5):
loop += 1
print 'gradual opening stage ' + loop + '/5'
#GPIO true- I know how to do this
time.sleep(divOpenTime) #working (:
#GPIO False- I know how to do this
time.sleep(15) #time between each interval fixed value
感谢埃德
错误是我们的最重要的部分帮助您
再次感谢:你做这个 用。请在这里发布错误。并感谢你开始在一个年龄时,我们大多数懒惰袋只是玩电子游戏:) – Ray
谢谢,希望增加更多的东西,如中继板和东西到我的家庭自动化项目,一旦我有了这个排序我'下次将添加错误@ Ray –