'Construct : Python - Print without new line

I am literally going crazy:

I am using the Pyhon Library : construct

What I want to acheive is to print the parsed stream on a single line, instead of having Value1 and Value 2 on different lines. Is there a way to do so?

data = 0xAF

from construct import *

testOut1 = BitStruct("Value1" /Nibble, "Value2" /Nibble).parse(data) 

print(testOut1)

This is WHat I have :

Container:

Value1 = 10
Value2 = 15

But I would line to have something like:

Value1 = 10, Value2 = 15


Solution 1:[1]

You can modify a string before you print it.

print(str(testOut1).replace("\n", ", "))

Solution 2:[2]

Best way to do it is to use

print('hello', end='')

In your case our code will be:

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='')

Or better :

print('Value1 =' + str(testOut1.Value1) + ',' + 'Value1 =' + str(testOut1.Value2))

Best regards,

Reference : https://128mots.com/index.php/2022/03/09/python-print-without-newline-2/

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 gilch
Solution 2 XCFzLoc