我剛剛花了大約30分鐘的時間調試並仔細檢查Python & C#代碼,發現我的struct.pack正在寫入錯誤的數據。當我把它分成不同的調用時,它工作正常。爲什麼分組的struct.pack會寫入錯誤的數據?
這是我
file.write(struct.pack("fffHf", kf_time/frame_divisor, kf_in_tangent, kf_out_tangent, kf_interpolation_type, kf_value))
這是我現在有
file.write(struct.pack("f", kf_time/frame_divisor))
file.write(struct.pack("f", kf_in_tangent))
file.write(struct.pack("f", kf_out_tangent))
file.write(struct.pack("H", kf_interpolation_type))
file.write(struct.pack("f", kf_value))
爲什麼第一個變化不寫,我所期望的數據之前有?與分別寫這些有什麼不同?
(文件以二進制模式打開,平臺是64位Windows的Python 3.5)
你能提供一個MCVE嗎? _https://stackoverflow.com/help/mcve_ – CIsForCookies
你在哪個平臺上?這是Python 2還是3?你是否以二進制模式打開文件? –
64位Windows。 Python 3.5。文件以二進制模式打開。 – aaro4130