kdlpy icon indicating copy to clipboard operation
kdlpy copied to clipboard

How to create a raw string node name?

Open eugenesvk opened this issue 2 years ago • 4 comments

It seems that Node only accepts regular Python strings as a name, but not kdl RawStrings

eugenesvk avatar Jan 20 '24 15:01 eugenesvk

Yes, RawStrings (and the other Value subclasses) are a type of value, suitable for an argument or a property value. I don't currently have any option to preserve the type of string used for a node name, or other non-value strings like tags or property names.

Currently my advice would be to stringify your object before passing it to Node's constructor. Do you have a reason to want to set one of the KDL types explicitly?

tabatkins avatar Jan 23 '24 02:01 tabatkins

I already use a string of another format on the input side, but I don't want to see those ugly \" escapes everywhere when printing KDL in the converted output, that's why I wanted to pass RawString type (which I currently do by having a random node name and having a rawstring as an argument)

eugenesvk avatar Jan 23 '24 10:01 eugenesvk

I've been considering switching to a "smart string choice" in the output (like I already have for deciding between printing as an ident or a string), so if there are " characters in the string I'll switch to using a raw string for output automatically. Would that be sufficient for you?

tabatkins avatar Jan 24 '24 17:01 tabatkins

Yes, that would work, thank you!

Although I've just realized that for this specific use case it might not work (there is a risk that the converted comment string will clash with a valid non-comment command if put in the node name, so I better maintain add an explicit non-command node name like - , but that would still be a good addition since for some other property values/arguments I do use RawString just to get rid of \"

eugenesvk avatar Jan 24 '24 17:01 eugenesvk