我試圖把(r"F:\Server\ ... "r")
它說:我不斷收到讀取問題[錯誤22]無效參數
file.write(float(u) + '\n') TypeError: unsupported operand type(s) for +: 'float' and 'str'.
當我不把r
是,它都將增加一倍\\對我說: :
read issue [Errno 22] Invalid argument: 'F:\\Server\\Frames\\Server_Stats_GUI\x08yteS-F_FS_Input.toff'.
這裏是我的代碼
import time
while True:
try:
file = open("F:\Server\Frames\Server_Stats_GUI\byteS-F_FS_Input.toff","r")
f = int(file.readline())
s = int(file.readline())
file.close()
except Exception as e:
# file is been written to, not enough data, whatever: ignore (but print a message)
print("read issue "+str(e))
else:
u = s - f
file = open("F:\Server\Frames\Server_Stats_GUI\bytesS-F_FS_Output","w") # update the file with the new result
file.write(float(u) + '\n')
file.close()
time.sleep(4) # wait 4 seconds
:您要添加float和string你需要嘗試追加新行之前將其轉換爲字符串:
或使用字符串格式化。把你的float轉換成一個字符串:'str(float(u))' – Julien
所以把file.write(float(u)改爲file.writestr(floau(u)) – ToxicLiquidz101