[英]Datetime is being printed with brackets , single quotes and comma
因此,我正在為樹莓派pi3項目的實時折線圖制作“日期溫度”。
我已經完成以下代碼:
import datetime
today = datetime.date.today()
dateformat = today.strftime("%d-%m-%Y")
testtemperature = 10
data = (dateformat,testtemperature)
data = str(data)
file= open("test.txt","a")
file.write(data)
file.close()
print (data)
但其打印或輸出:
('15-05-2017', 10)
代替:
“ 15-05-2017 10”如何刪除括號,單引號和逗號? 謝謝。
你可以寫:
print(*data)
這使:
15-05-2017 10
*
表示您希望“解包”元組data
並分別打印每個元組data
。
定義數據時,請使用字符串格式。
data = "{} {}".format(dateformat,testtemperature)
在上下文中,它將是:
import datetime
today = datetime.date.today()
dateformat = today.strftime("%d-%m-%Y")
testtemperature = 10
data = "{} {}".format(dateformat,testtemperature)
file = open("test.txt","a")
file.write(data)
file.close()
print (data) # prints "15-05-2017 10"
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.