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.

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

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 <hollyshort21@gmail.com> wrote:

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

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 <hollyshort21@gmail.com> wrote:
participants (4)
-
Anders Hovmöller
-
Artemis
-
Brandt Bucher
-
David Mertz