PyCall.jl
PyCall.jl copied to clipboard
Misalignment of first line in multiline show of PyObject
PyObjects whose pystring method returns a multiline string have their first row misaligned when shown. For example
using PyCall
qiskit = pyimport("qiskit")
qc = qiskit.QuantumCircuit(1)
qc.x(0)
qc.draw()
gives
PyObject ┌───┐
q_0: ┤ X ├
└───┘
A fix would be to replace
function show(io::IO, o::PyObject)
print(io, "PyObject $(pystring(o))")
end
with
function show(io::IO, o::PyObject)
str = pystring(o)
sep = contains(str, "\n") ? "\n" : " " # Avoid misaligning the first line for multiline prints
print(io, "PyObject$sep$str")
end
which gives the following print instead.
PyObject
┌───┐
q_0: ┤ X ├
└───┘
Can you give an example?
There was some kind of example in the original post, but I've updated it to make it more clear.