xflr6/graphviz

Doesn't print the vertical bar if uses f-string

Closed this issue · 2 comments

Notebook Sample from repo

dotA = Digraph(format="svg", graph_attr={"rankdir": "LR"})

x = 1
y = 2.0
dotA.node(
    name="A",
    label=f"{x}|Data {y:.4f}",
    shape="record",
)
dotA

Results in the following below which is not intended

image

While using the old string formatting of python

dotB = Digraph(format="svg", graph_attr={"rankdir": "LR"})

dotB.node(
    name="B",
    label="{ %s | data: %.4f }" % (1, 2.0),
    shape="record",
)
dotB

Results in the desired format

image

Hey. Sorry, but I don't understand where you see a possible bug within graphviz here.

IIUC this is the value you want to pass as label:

>>> x = 1
>>> y = 2.0
>>> print('{ %s | data: %.4f }' % (x, y))
{ 1 | data: 2.0000 }

Clearly you are not getting this result with f'{x} | data: {y:.4f}' you are using above (no curly braces in your f-string).

This is as expected, right? Maybe you are just asking how to create the literal curly braces with a Python f-string?

That would be f'{{ {x} | data: {y:.4f} }}' (need to be doubled).

My bad, and many thanks for the help!