나는 날씨 데이터를 보내고 있다는 LED 표시가 있지만 온도 문제가 발생하여 표시가 읽히지 않을 것이라고 생각하는 십진수로 읽습니다.이 오류가 발생합니다.
File "/usr/local/lib/python3.4/dist-packages/pyledsign/minisign.py", line 276, in processtags
data=data.replace('<f:normal>',str(normal,'latin-1'))
AttributeError: 'float' object has no attribute 'replace'
다음은 기호에 대한 내 코드입니다. 이것을 사인에 보낼 때 오류가 발생합니다.
mysign.queuemsg(data=current_weather.temperature, speed=2).
그래서 날씨 온도가 항상 int로 읽힐 것이라고 어떻게 말할 수 있는지 궁금했습니다. 주위에 int ()를 두는 것은 작동하지 않습니다.
#!/usr/bin/python
import datetime
import forecastio
from pyledsign.minisign import MiniSign
def main():
"""
Run load_forecast() with the given lat, lng, and time arguments.
"""
api_key = 'my api key'
lat = 42.3314
lng = -83.0458
forecast = forecastio.load_forecast(api_key, lat, lng,)
mysign = MiniSign(devicetype='sign')
print ("===========Currently Data=========")
current_weather = forecast.currently()
print (current_weather.summary)
print (current_weather.temperature)
mysign.queuemsg(data=current_weather.summary, speed=2)
mysign.queuemsg(data=current_weather.temperature, speed=2)
mysign.sendqueue(device='/dev/ttyUSB0')
print ("===========Daily Data=========")
by_day = forecast.daily()
print ("Daily Summary: %s" %(by_day.summary))
mysign.queuemsg(data=by_day.summary)
mysign.sendqueue(device='/dev/ttyUSB0')
if __name__ == "__main__":
main()
오류는 문자열을 예상하는 메소드에서 발생합니다.
숫자 값을 부호로 보내기 전에 명시 적으로 문자열로 변환해야합니다.
mysign.queuemsg(data=str(current_weather.temperature), speed=2)
연결과 같은 추가 문자열 작업을 수행 할 수도 있습니다.
mysign.queuemsg(data=str(current_weather.temperature) + ' degrees', speed=2)
또한 문자열 형식 을 사용 하여 값을 문자열로 변환하고 소수 자릿수 등을 제어 할 수 있습니다. 문자열 형식화는 Python 2와 Python 3에서 다르게 작동합니다. 예를 들어 Python 2에서는 다음을 수행 할 수 있습니다.
mysign.queuemsg(data='%s degrees' % current_weather.temperature, speed=2)
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다