[英]Construct : Python - Print without new line
我真的快瘋了:
我正在使用 Pyhon 庫:構造
我想要實現的是在一行上打印解析的 stream,而不是在不同的行上打印 Value1 和 Value 2。 有沒有辦法這樣做?
data = 0xAF
from construct import *
testOut1 = BitStruct("Value1" /Nibble, "Value2" /Nibble).parse(data)
print(testOut1)
這就是我所擁有的:
Container:
Value1 = 10
Value2 = 15
但我會排隊有類似的東西:
Value1 = 10, Value2 = 15
您可以在打印之前修改字符串。
print(str(testOut1).replace("\n", ", "))
最好的方法是使用
print('hello', end='')
在您的情況下,我們的代碼將是:
data = 0xAF
from construct import *
testOut1 = BitStruct("Value1" /Nibble, "Value2" /Nibble).parse(data)
print('Value1 =' + str(testOut1.Value1) + ',', end='')
print('Value2 =' + str(testOut1.Value2) + '', end='')
或更好:
print('Value1 =' + str(testOut1.Value1) + ',' + 'Value1 =' + str(testOut1.Value2))
此致,
參考: https://128mots.com/index.php/2022/03/09/python-print-without-newline-2/
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.