“ NB my PyCharm-settings grumble whenever I create an identifier which is only used once (and perhaps, soon after it was established). I understand the (space) optimisation, but prefer to trade that for 'readability'. “ I haven’t seen that one. What I get is warnings about:
def is_adult( self )->bool: LEGAL_AGE_US = 21 return LEGAL_AGE It doesn’t like LEGAL_AGE_US being all caps if declared in a function. From: Python-list <python-list-bounces+gweatherby=uchc....@python.org> on behalf of dn via Python-list <python-list@python.org> Date: Thursday, February 23, 2023 at 5:46 PM To: python-list@python.org <python-list@python.org> Subject: Re: Line continuation and comments *** Attention: This is an external email. Use caution responding, opening attachments or clicking on links. *** On 22/02/2023 21.49, Robert Latest via Python-list wrote: > I found myself building a complicated logical condition with many ands and ors > which I made more manageable by putting the various terms on individual lines > and breaking them with the "\" line continuation character. In this context it > would have been nice to be able to add comments to lines terms which of course > isn't possible because the backslash must be the last character on the line. > > Question: If the Python syntax were changed to allow comments after > line-ending > backslashes, would it break any existing code? I can't think of an example. Alternative to suggestions thus far: break the complex* logical condition into 'labelled' components, and then combine those (likely shorter) into the condition: if person.is_adult and person.is_qualified and person.has_funds ... which presumes that at some previous time we have, for example: def is_adult( self )->bool: return 21 <= self.age <= 65 (not that I'd like to see those two 'magic-constants' in anyone's code, but (hopefully) the idea has been conveyed...) * "simple is better than..." NB my PyCharm-settings grumble whenever I create an identifier which is only used once (and perhaps, soon after it was established). I understand the (space) optimisation, but prefer to trade that for 'readability'. -- Regards, =dn -- https://urldefense.com/v3/__https://mail.python.org/mailman/listinfo/python-list__;!!Cn_UX_p3!ghW7FUX8GJF79keLaMyaVewXcKw3jexuxF-QJh8h564QBAIoi2ez20tIl5fg762Rcfnh-XA4sG53CKt2NYgHpTWlyA$<https://urldefense.com/v3/__https:/mail.python.org/mailman/listinfo/python-list__;!!Cn_UX_p3!ghW7FUX8GJF79keLaMyaVewXcKw3jexuxF-QJh8h564QBAIoi2ez20tIl5fg762Rcfnh-XA4sG53CKt2NYgHpTWlyA$> -- https://mail.python.org/mailman/listinfo/python-list