Skip to content

Python char conversion enforces string length of 1

David Gobbi requested to merge dgobbi/vtk:python-char-length into master

Previously, if a VTK method required a char, then from Python it was possible to pass '' (empty string), or a string of any length if the second character was null, e.g. 'h\0llo world'. Now the length of the string is strictly enforced to be one.

Best practice is to pass chr(n) to methods that intend to use the char as a number, or to pass 'a' to methods that intend to use the char as a character. For a null character, '\0' and chr(0) are equally suitable, but '' will raise a ValueError:

ValueError: Method argument 1: string of length 1, ord < 256 is required
Edited by David Gobbi

Merge request reports