Guidelines on ZWSP
What should one do when one wants to put a zero width space or other invisible character in code? These are often not displayed in editors, which can lead to confusion. I see two solutions: - include it but add a comment noting it - use the chr function to get the character (and add a comment saying what it is) Where should a guideline for this go (PEP 8?)? What should the guideline be (one of these or something else?)? This is my first time contributing in any way to Python, please excuse me if I've done it in the wrong place/format.
On 10 Nov 2019, at 02:22, Artemis
wrote: What should one do when one wants to put a zero width space or other invisible character in code? These are often not displayed in editors, which can lead to confusion. I see two solutions: - include it but add a comment noting it - use the chr function to get the character (and add a comment saying what it is) Where should a guideline for this go (PEP 8?)? What should the guideline be (one of these or something else?)?
In my opinion the best way is '\N{ZERO WIDTH SPACE}'
Welcome! I would just define a module level constant that uses a Unicode escape sequence. The code is self-documenting, and doesn’t require the runtime overhead of the chr function: ZERO_WIDTH_SPACE = "\u200b" I personally don’t think this is a common/important enough case to be documented any further (it’s now here on the mailing list archives). PEP 8 is more of a style guide, not a design guide! Brandt
On Nov 10, 2019, at 06:33, Artemis
wrote: What should one do when one wants to put a zero width space or other invisible character in code? These are often not displayed in editors, which can lead to confusion. I see two solutions: - include it but add a comment noting it - use the chr function to get the character (and add a comment saying what it is) Where should a guideline for this go (PEP 8?)? What should the guideline be (one of these or something else?)?
This is my first time contributing in any way to Python, please excuse me if I've done it in the wrong place/format. _______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-leave@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/6XBJGG... Code of Conduct: http://python.org/psf/codeofconduct/
Just my opinion, I do not think this belongs in PEP8 or official guidelines.
Different editors will vary, of course, in how they handle "invisible"
characters. But since various people will read your code, I think it's
generally friendlier to use a name or Unicode escape rather than a quoted
literal.
E.g.
foobar = "foo\u200bbar" # zero-width space inside
Or if you use it often:
zw = "\u200b"
foobar = f"foo{zw}bar"
On Sun, Nov 10, 2019, 9:34 AM Artemis
What should one do when one wants to put a zero width space or other invisible character in code? These are often not displayed in editors, which can lead to confusion. I see two solutions: - include it but add a comment noting it - use the chr function to get the character (and add a comment saying what it is) Where should a guideline for this go (PEP 8?)? What should the guideline be (one of these or something else?)?
This is my first time contributing in any way to Python, please excuse me if I've done it in the wrong place/format. _______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-leave@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/6XBJGG... Code of Conduct: http://python.org/psf/codeofconduct/
participants (4)
-
Anders Hovmöller
-
Artemis
-
Brandt Bucher
-
David Mertz