• semi colonic

    From [email protected]@21:1/5 to Hen Hanna on Wed Feb 22 19:58:42 2023
    Thomas,

    This is one of many little twists I see between languages where one feature impacts use or even the need for another feature.

    So can anyone point to places in Python where a semicolon is part of a best
    or even good way to do anything?

    Some older languages had simple parsers/compilers that needed some way to
    know when a conceptual line of code was DONE and the semi-colon was a choice for making that clear. But some languages seem to only continue looking past
    an end-of-line if they detect some serious reason to assume you are in
    middle of something. An unmatched open parenthesis or square bracket might
    be enough, and in some languages a curly brace.

    Python mainly has a concept of indentation and blank lines as one part of
    the guidance. Continuing lines is possible, if done carefully.

    But consider the lowly comma. Some languages may assume more is to come if
    it is dangled at the end of a line. But in a language that supports a
    dangling comma such as in making a tuple, how is the interpreter to know
    more is to come?

    a = 5,
    a
    (5,)

    a = 5, \
    ... 6
    a
    (5, 6)

    Well, one possible use of a semi-colon is to make short one-liner functions like this:

    def twoByFour(a): sq = a*a; forth = sq*sq; return((sq, forth))

    There is no reason, of course, that could not be done in multiple indented lines or other ways.

    So if it was allowed in something like a lambda creation, it could be useful but it isn't!

    About the only thing that I can think of is if someone wishes to compress a file of python code a bit. The indentation can add up but a semi-colon does
    not solve all such problems.

    Would anything serious break if it was deprecated for use as a statement terminator? Then again, is it hurting anything? If it stopped being used
    this way, could it later be introduced as some new language feature or
    operator such as we now have a := b as a reuse of the colon, maybe a
    semicolon could be useful at least until someone decides to allow additional Unicode characters!

    Now if there are serious reasons to use semi-colon in python, great. If not,
    it is a historical artifact.

    -----Original Message-----
    From: Python-list <python-list-bounces+avi.e.gross=[email protected]> On Behalf Of Thomas Passin
    Sent: Wednesday, February 22, 2023 7:24 PM
    To: [email protected]
    Subject: Re: Introspecting the variable bound to a function argument

    On 2/22/2023 3:12 PM, Hen Hanna wrote:
    On Wednesday, February 22, 2023 at 2:32:57 AM UTC-8, Anton Shepelev wrote:
    Hello, all.

    Does Python have an instrospection facility that can determine to
    which outer variable a function argument is bound, e.g.:

    v1 = 5;
    v2 = 5;


    do some Python coders like to end lines with ; ?

    Very few, probably. It's not harmful but adds unnecessary visual clutter.


    def f(a):
    print(black_magic(a)) # or
    black_magic('a')

    f(v1) # prints: v1
    f(v2) # prints: v2


    the term [call by name] suggests this should be possible.


    30 years ago... i used to think about this type of thing A LOT ---
    ------- CBR, CBV, CBN, (call by value), (call by name)....
    etc.


    --
    https://mail.python.org/mailman/listinfo/python-list

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Thomas Passin@21:1/5 to [email protected] on Wed Feb 22 21:04:45 2023
    On 2/22/2023 7:58 PM, [email protected] wrote:
    Thomas,

    This is one of many little twists I see between languages where one feature impacts use or even the need for another feature.

    So can anyone point to places in Python where a semicolon is part of a best or even good way to do anything?

    Mostly I use it to run small commands on the command line with python
    -c. e.g.

    python -c "import sys;print('\n'.join(sys.path))"

    This is handy enough that I wouldn't like to do without.

    Another place I use the semicolon (once in a while) is for quick
    debugging. I might add as line like, perhaps,

    import os; print(os.path.exists(filename))

    This way I can get rid of the debugging statement by deleting that
    single line. This is non only quicker but I'm less likely to delete too
    much by mistake.

    Some older languages had simple parsers/compilers that needed some way to know when a conceptual line of code was DONE and the semi-colon was a choice for making that clear. But some languages seem to only continue looking past an end-of-line if they detect some serious reason to assume you are in
    middle of something. An unmatched open parenthesis or square bracket might
    be enough, and in some languages a curly brace.

    Python mainly has a concept of indentation and blank lines as one part of
    the guidance. Continuing lines is possible, if done carefully.

    But consider the lowly comma. Some languages may assume more is to come if
    it is dangled at the end of a line. But in a language that supports a dangling comma such as in making a tuple, how is the interpreter to know
    more is to come?

    a = 5,
    a
    (5,)

    a = 5, \
    ... 6
    a
    (5, 6)

    Well, one possible use of a semi-colon is to make short one-liner functions like this:

    def twoByFour(a): sq = a*a; forth = sq*sq; return((sq, forth))

    There is no reason, of course, that could not be done in multiple indented lines or other ways.

    So if it was allowed in something like a lambda creation, it could be useful but it isn't!

    About the only thing that I can think of is if someone wishes to compress a file of python code a bit. The indentation can add up but a semi-colon does not solve all such problems.

    Would anything serious break if it was deprecated for use as a statement terminator? Then again, is it hurting anything? If it stopped being used
    this way, could it later be introduced as some new language feature or operator such as we now have a := b as a reuse of the colon, maybe a semicolon could be useful at least until someone decides to allow additional Unicode characters!

    Now if there are serious reasons to use semi-colon in python, great. If not, it is a historical artifact.

    -----Original Message-----
    From: Python-list <python-list-bounces+avi.e.gross=[email protected]> On Behalf Of Thomas Passin
    Sent: Wednesday, February 22, 2023 7:24 PM
    To: [email protected]
    Subject: Re: Introspecting the variable bound to a function argument

    On 2/22/2023 3:12 PM, Hen Hanna wrote:
    On Wednesday, February 22, 2023 at 2:32:57 AM UTC-8, Anton Shepelev wrote: >>> Hello, all.

    Does Python have an instrospection facility that can determine to
    which outer variable a function argument is bound, e.g.:

    v1 = 5;
    v2 = 5;


    do some Python coders like to end lines with ; ?

    Very few, probably. It's not harmful but adds unnecessary visual clutter.


    def f(a):
    print(black_magic(a)) # or
    black_magic('a')

    f(v1) # prints: v1
    f(v2) # prints: v2


    the term [call by name] suggests this should be possible.


    30 years ago... i used to think about this type of thing A LOT ---
    ------- CBR, CBV, CBN, (call by value), (call by name)....
    etc.


    --
    https://mail.python.org/mailman/listinfo/python-list


    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Rob Cliffe@21:1/5 to Thomas Passin on Thu Feb 23 02:20:28 2023
    On 23/02/2023 02:04, Thomas Passin wrote:
    On 2/22/2023 7:58 PM, [email protected] wrote:


    So can anyone point to places in Python where a semicolon is part of
    a best
    or even good way to do anything?

     I use the semicolon (once in a while) is for quick debugging.  I
    might add as line like, perhaps,

    import os; print(os.path.exists(filename))

    This way I can get rid of the debugging statement by deleting that
    single line.  This is non only quicker but I'm less likely to delete
    too much by mistake.

    I do exactly the same.
    Rob Cliffe

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Hen Hanna@21:1/5 to Rob Cliffe on Wed Feb 22 18:25:00 2023
    On Wednesday, February 22, 2023 at 6:21:13 PM UTC-8, Rob Cliffe wrote:
    On 23/02/2023 02:04, Thomas Passin wrote:
    On 2/22/2023 7:58 PM, [email protected] wrote:


    So can anyone point to places in Python where a semicolon is part of
    a best
    or even good way to do anything?

    I use the semicolon (once in a while) is for quick debugging. I
    might add as line like, perhaps,

    import os; print(os.path.exists(filename))

    This way I can get rid of the debugging statement by deleting that
    single line. This is non only quicker but I'm less likely to delete
    too much by mistake.


    I do exactly the same.
    Rob Cliffe


    i sometimes put extra commas... as:

    [ 1, 2, 3, 4, ]

    so it is (or may be) easier to add things later.

    ----------- i can think of putting extra final ; for the same reason.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From [email protected]@21:1/5 to [email protected] on Wed Feb 22 22:42:10 2023
    That seems like a reasonable if limited use of a semi-colon, Thomas.

    Of course, most shells will allow a multi-line argument too like some AWK scripts I have written with a quote on the first line followed by multiple lines of properly formatted code and a closing quote.

    Python though can get touchy about getting just the right amount of
    indentation and simple attempts to break your program up into two lines

    python -c "import sys
    print('\n'.join(sys.path))"


    DO not work so well on some shells.

    So, yes, I agree. But I tried this on bash under Cygwin on windows using a "here" document and it worked fine with multiple lines so something to
    consider with no semicolons:

    $ python <<!
    import sys
    print('\n'.join(sys.path))
    !

    /usr/lib/python2.7/site-packages/pylint-1.3.1-py2.7.egg /usr/lib/python2.7/site-packages/astroid-1.3.4-py2.7.egg /usr/lib/python2.7/site-packages/six-1.9.0-py2.7.egg
    /usr/lib/python27.zip
    /usr/lib/python2.7
    /usr/lib/python2.7/plat-cygwin
    /usr/lib/python2.7/lib-tk
    /usr/lib/python2.7/lib-old
    /usr/lib/python2.7/lib-dynload
    /usr/lib/python2.7/site-packages
    /usr/lib/python2.7/site-packages/gtk-2.0

    -----Original Message-----
    From: Python-list <python-list-bounces+avi.e.gross=[email protected]> On Behalf Of Thomas Passin
    Sent: Wednesday, February 22, 2023 9:05 PM
    To: [email protected]
    Subject: Re: semi colonic

    On 2/22/2023 7:58 PM, [email protected] wrote:
    Thomas,

    This is one of many little twists I see between languages where one
    feature impacts use or even the need for another feature.

    So can anyone point to places in Python where a semicolon is part of a
    best or even good way to do anything?

    Mostly I use it to run small commands on the command line with python -c.
    e.g.

    python -c "import sys;print('\n'.join(sys.path))"

    This is handy enough that I wouldn't like to do without.

    Another place I use the semicolon (once in a while) is for quick debugging.
    I might add as line like, perhaps,

    import os; print(os.path.exists(filename))

    This way I can get rid of the debugging statement by deleting that single
    line. This is non only quicker but I'm less likely to delete too much by mistake.

    Some older languages had simple parsers/compilers that needed some way
    to know when a conceptual line of code was DONE and the semi-colon was
    a choice for making that clear. But some languages seem to only
    continue looking past an end-of-line if they detect some serious
    reason to assume you are in middle of something. An unmatched open parenthesis or square bracket might be enough, and in some languages a
    curly brace.

    Python mainly has a concept of indentation and blank lines as one part
    of the guidance. Continuing lines is possible, if done carefully.

    But consider the lowly comma. Some languages may assume more is to
    come if it is dangled at the end of a line. But in a language that
    supports a dangling comma such as in making a tuple, how is the
    interpreter to know more is to come?

    a = 5,
    a
    (5,)

    a = 5, \
    ... 6
    a
    (5, 6)

    Well, one possible use of a semi-colon is to make short one-liner
    functions like this:

    def twoByFour(a): sq = a*a; forth = sq*sq; return((sq, forth))

    There is no reason, of course, that could not be done in multiple
    indented lines or other ways.

    So if it was allowed in something like a lambda creation, it could be
    useful but it isn't!

    About the only thing that I can think of is if someone wishes to
    compress a file of python code a bit. The indentation can add up but a semi-colon does not solve all such problems.

    Would anything serious break if it was deprecated for use as a
    statement terminator? Then again, is it hurting anything? If it
    stopped being used this way, could it later be introduced as some new language feature or operator such as we now have a := b as a reuse of
    the colon, maybe a semicolon could be useful at least until someone
    decides to allow additional Unicode characters!

    Now if there are serious reasons to use semi-colon in python, great.
    If not, it is a historical artifact.

    -----Original Message-----
    From: Python-list
    <python-list-bounces+avi.e.gross=[email protected]> On Behalf Of
    Thomas Passin
    Sent: Wednesday, February 22, 2023 7:24 PM
    To: [email protected]
    Subject: Re: Introspecting the variable bound to a function argument

    On 2/22/2023 3:12 PM, Hen Hanna wrote:
    On Wednesday, February 22, 2023 at 2:32:57 AM UTC-8, Anton Shepelev
    wrote:
    Hello, all.

    Does Python have an instrospection facility that can determine to
    which outer variable a function argument is bound, e.g.:

    v1 = 5;
    v2 = 5;


    do some Python coders like to end lines with ; ?

    Very few, probably. It's not harmful but adds unnecessary visual clutter.


    def f(a):
    print(black_magic(a)) # or
    black_magic('a')

    f(v1) # prints: v1
    f(v2) # prints: v2


    the term [call by name] suggests this should be possible.


    30 years ago... i used to think about this type of thing A LOT ---
    ------- CBR, CBV, CBN, (call by value), (call by
    name)....
    etc.


    --
    https://mail.python.org/mailman/listinfo/python-list


    --
    https://mail.python.org/mailman/listinfo/python-list

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Thomas Passin@21:1/5 to [email protected] on Wed Feb 22 23:26:19 2023
    On 2/22/2023 10:42 PM, [email protected] wrote:
    That seems like a reasonable if limited use of a semi-colon, Thomas.

    Of course, most shells will allow a multi-line argument too like some AWK scripts I have written with a quote on the first line followed by multiple lines of properly formatted code and a closing quote.

    "Most shells"... got to include cmd.exe, don't forget.

    Python though can get touchy about getting just the right amount of indentation and simple attempts to break your program up into two lines

    python -c "import sys
    print('\n'.join(sys.path))"


    DO not work so well on some shells.

    So, yes, I agree. But I tried this on bash under Cygwin on windows using a "here" document and it worked fine with multiple lines so something to consider with no semicolons:

    $ python <<!
    import sys
    print('\n'.join(sys.path))
    !

    /usr/lib/python2.7/site-packages/pylint-1.3.1-py2.7.egg /usr/lib/python2.7/site-packages/astroid-1.3.4-py2.7.egg /usr/lib/python2.7/site-packages/six-1.9.0-py2.7.egg
    /usr/lib/python27.zip
    /usr/lib/python2.7
    /usr/lib/python2.7/plat-cygwin
    /usr/lib/python2.7/lib-tk
    /usr/lib/python2.7/lib-old
    /usr/lib/python2.7/lib-dynload
    /usr/lib/python2.7/site-packages
    /usr/lib/python2.7/site-packages/gtk-2.0

    -----Original Message-----
    From: Python-list <python-list-bounces+avi.e.gross=[email protected]> On Behalf Of Thomas Passin
    Sent: Wednesday, February 22, 2023 9:05 PM
    To: [email protected]
    Subject: Re: semi colonic

    On 2/22/2023 7:58 PM, [email protected] wrote:
    Thomas,

    This is one of many little twists I see between languages where one
    feature impacts use or even the need for another feature.

    So can anyone point to places in Python where a semicolon is part of a
    best or even good way to do anything?

    Mostly I use it to run small commands on the command line with python -c. e.g.

    python -c "import sys;print('\n'.join(sys.path))"

    This is handy enough that I wouldn't like to do without.

    Another place I use the semicolon (once in a while) is for quick debugging.
    I might add as line like, perhaps,

    import os; print(os.path.exists(filename))

    This way I can get rid of the debugging statement by deleting that single line. This is non only quicker but I'm less likely to delete too much by mistake.

    Some older languages had simple parsers/compilers that needed some way
    to know when a conceptual line of code was DONE and the semi-colon was
    a choice for making that clear. But some languages seem to only
    continue looking past an end-of-line if they detect some serious
    reason to assume you are in middle of something. An unmatched open
    parenthesis or square bracket might be enough, and in some languages a
    curly brace.

    Python mainly has a concept of indentation and blank lines as one part
    of the guidance. Continuing lines is possible, if done carefully.

    But consider the lowly comma. Some languages may assume more is to
    come if it is dangled at the end of a line. But in a language that
    supports a dangling comma such as in making a tuple, how is the
    interpreter to know more is to come?

    a = 5,
    a
    (5,)

    a = 5, \
    ... 6
    a
    (5, 6)

    Well, one possible use of a semi-colon is to make short one-liner
    functions like this:

    def twoByFour(a): sq = a*a; forth = sq*sq; return((sq, forth))

    There is no reason, of course, that could not be done in multiple
    indented lines or other ways.

    So if it was allowed in something like a lambda creation, it could be
    useful but it isn't!

    About the only thing that I can think of is if someone wishes to
    compress a file of python code a bit. The indentation can add up but a
    semi-colon does not solve all such problems.

    Would anything serious break if it was deprecated for use as a
    statement terminator? Then again, is it hurting anything? If it
    stopped being used this way, could it later be introduced as some new
    language feature or operator such as we now have a := b as a reuse of
    the colon, maybe a semicolon could be useful at least until someone
    decides to allow additional Unicode characters!

    Now if there are serious reasons to use semi-colon in python, great.
    If not, it is a historical artifact.

    -----Original Message-----
    From: Python-list
    <python-list-bounces+avi.e.gross=[email protected]> On Behalf Of
    Thomas Passin
    Sent: Wednesday, February 22, 2023 7:24 PM
    To: [email protected]
    Subject: Re: Introspecting the variable bound to a function argument

    On 2/22/2023 3:12 PM, Hen Hanna wrote:
    On Wednesday, February 22, 2023 at 2:32:57 AM UTC-8, Anton Shepelev
    wrote:
    Hello, all.

    Does Python have an instrospection facility that can determine to
    which outer variable a function argument is bound, e.g.:

    v1 = 5;
    v2 = 5;


    do some Python coders like to end lines with ; ?

    Very few, probably. It's not harmful but adds unnecessary visual clutter. >>

    def f(a):
    print(black_magic(a)) # or
    black_magic('a')

    f(v1) # prints: v1
    f(v2) # prints: v2


    the term [call by name] suggests this should be possible.


    30 years ago... i used to think about this type of thing A LOT ---
    ------- CBR, CBV, CBN, (call by value), (call by
    name)....
    etc.


    --
    https://mail.python.org/mailman/listinfo/python-list


    --
    https://mail.python.org/mailman/listinfo/python-list


    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From rbowman@21:1/5 to Hen Hanna on Thu Feb 23 06:13:28 2023
    On Wed, 22 Feb 2023 18:25:00 -0800 (PST), Hen Hanna wrote:


    i sometimes put extra commas... as:

    [ 1, 2, 3, 4, ]

    so it is (or may be) easier to add things later.


    That can bite you with things like JSON that aren't very forgiving. The
    same can be said for single quotes that may or may not work as intended.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Greg Ewing@21:1/5 to [email protected] on Thu Feb 23 19:27:30 2023
    On 23/02/23 1:58 pm, [email protected] wrote:

    Would anything serious break if it was deprecated for use as a statement terminator?

    Well, it would break all the code of people who like to
    write code that way. They might get a bit miffed if we
    decide that their code is not serious. :-)

    On the other hand, if they really want to, they will still
    be able to abuse semicolons by doing this sort of thing:

    a = 5; pass
    b = 7; pass
    c = a * b; pass

    Then everyone will know it's some really serious code!

    --
    Greg

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From [email protected]@21:1/5 to [email protected] on Thu Feb 23 10:15:49 2023
    Greg,

    How did you know that was the method I used to indicate I had properly
    debugged and tested a line of code?

    a = 5; pass
    b = 7; pass
    c = a * b; pass

    Then I switched to using comments:

    a = 5 # pass
    b = 7 # pass
    c = a * b # fail

    And would you believe it still worked!

    OK, I am just kidding if anyone is taking this seriously.


    -----Original Message-----
    From: Python-list <python-list-bounces+avi.e.gross=[email protected]> On Behalf Of Greg Ewing via Python-list
    Sent: Thursday, February 23, 2023 1:28 AM
    To: [email protected]
    Subject: Re: semi colonic

    On 23/02/23 1:58 pm, [email protected] wrote:

    Would anything serious break if it was deprecated for use as a
    statement terminator?

    Well, it would break all the code of people who like to write code that way. They might get a bit miffed if we decide that their code is not serious. :-)

    On the other hand, if they really want to, they will still be able to abuse semicolons by doing this sort of thing:

    a = 5; pass
    b = 7; pass
    c = a * b; pass

    Then everyone will know it's some really serious code!

    --
    Greg
    --
    https://mail.python.org/mailman/listinfo/python-list

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Dieter Maurer@21:1/5 to Thomas Passin on Thu Feb 23 19:17:03 2023
    Thomas Passin wrote at 2023-2-22 21:04 -0500:
    On 2/22/2023 7:58 PM, [email protected] wrote:
    ...
    So can anyone point to places in Python where a semicolon is part of a best >> or even good way to do anything?

    Mostly I use it to run small commands on the command line with python
    -c. e.g.

    python -c "import sys;print('\n'.join(sys.path))"

    This is handy enough that I wouldn't like to do without.

    Another place I use the semicolon (once in a while) is for quick
    debugging. I might add as line like, perhaps,

    import os; print(os.path.exists(filename))

    I also see, `;` occasionally in `*.pth` files.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Rob Cliffe@21:1/5 to [email protected] on Thu Feb 23 02:10:52 2023
    On 23/02/2023 00:58, [email protected] wrote:
    So can anyone point to places in Python where a semicolon is part of a best or even good way to do anything?


    Yes.  Take this bit of toy code which I just dreamed up.  (Of course it
    is toy code; don't bother telling me how it could be written better.) 
    If it looks a bit ragged, pretend it is in a fixed font.

    if dow==0: day="Mon"; calcPay()
    if dow==1: day="Tue"; calcPay()
    if dow==2: day="Wed"; calcPay()
    if dow==3: day="Thu"; calcPay()
    if dow==4: day="Fri"; calcpay()
    if dow==5: day="Sat"; calcPay(rate=1.5)
    if dow==6: day="Sun"; calcPay(rate=2)

    The point is: when you have several short bits of code with an identical
    or similar pattern, *vertically aligning* the corresponding parts can
    IMO make it much easier to read the code and easier to spot errors.
    Compare this:

    if dow==0:
        day="Mon"
        calcPay()
    if dow==1:
        day="Tue"
        calcPay()
    if dow==2:
        day="Wed"
        calcPay()
    if dow==3:
        day="Thu"
        calcPay()
    if dow==4:
        day="Fri"
        calcpay()
    if dow==5:
        day="Sat"
        calcPay(rate=1.5)
    if dow==6:
        day="Sun"
        calcPay(rate=2)

    Not so easy to spot the mistake now, is it?
    Not to mention the saving of vertical space.

    Best wishes
    Rob Cliffe
    PS If you really care, I can send you a more complicated example of real
    code from one of my programs which is HUGELY more readable when laid out
    in this way.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From [email protected]@21:1/5 to [email protected] on Thu Feb 23 13:57:09 2023
    That is a reasonable use, Rob, albeit I would refactor that example in quite a few ways so the need for a semicolon disappears even for lining things up.

    So to extrapolate, perhaps a related example might be as simple as wanting to initialialize multiple variables together might suffice as in:

    if dow == 0: hours_worked = 8; overtime = False

    Of course some monstrosities are now possible for such a scenario such as


    if dow == 0: hours_worked, overtime = 8, False

    Not that readable.

    I repeat, there is nothing wrong with a language having a feature like a semi-colon even if it is mainly syntactic sugar. Just wondering if it was widely used or even essential. My thought was that python evolved when some languages really needed a
    terminator but as it went another way, using indentation and sometimes blank lines, ...

    I am not sure what Dieter meant about seeing semicolons in .pth files. I expect to see them in all kinds of files containing python code or anything created with a structure that chooses to include it.

    -----Original Message-----
    From: Python-list <python-list-bounces+avi.e.gross=[email protected]> On Behalf Of Rob Cliffe via Python-list
    Sent: Wednesday, February 22, 2023 9:11 PM
    To: [email protected]
    Subject: Re: semi colonic



    On 23/02/2023 00:58, [email protected] wrote:
    So can anyone point to places in Python where a semicolon is part of a
    best or even good way to do anything?


    Yes. Take this bit of toy code which I just dreamed up. (Of course it is toy code; don't bother telling me how it could be written better.) If it looks a bit ragged, pretend it is in a fixed font.

    if dow==0: day="Mon"; calcPay()
    if dow==1: day="Tue"; calcPay()
    if dow==2: day="Wed"; calcPay()
    if dow==3: day="Thu"; calcPay()
    if dow==4: day="Fri"; calcpay()
    if dow==5: day="Sat"; calcPay(rate=1.5)
    if dow==6: day="Sun"; calcPay(rate=2)

    The point is: when you have several short bits of code with an identical or similar pattern, *vertically aligning* the corresponding parts can IMO make it much easier to read the code and easier to spot errors.
    Compare this:

    if dow==0:
    day="Mon"
    calcPay()
    if dow==1:
    day="Tue"
    calcPay()
    if dow==2:
    day="Wed"
    calcPay()
    if dow==3:
    day="Thu"
    calcPay()
    if dow==4:
    day="Fri"
    calcpay()
    if dow==5:
    day="Sat"
    calcPay(rate=1.5)
    if dow==6:
    day="Sun"
    calcPay(rate=2)

    Not so easy to spot the mistake now, is it?
    Not to mention the saving of vertical space.

    Best wishes
    Rob Cliffe
    PS If you really care, I can send you a more complicated example of real code from one of my programs which is HUGELY more readable when laid out in this way.

    --
    https://mail.python.org/mailman/listinfo/python-list

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Rob Cliffe@21:1/5 to Hen Hanna on Thu Feb 23 11:07:42 2023
    On 23/02/2023 02:25, Hen Hanna wrote:

    i sometimes put extra commas... as:

    [ 1, 2, 3, 4, ]
    That is a good idea.
    Even more so when the items are on separate lines:
        [
            "spam",
            "eggs",
            "cheese",
        ]
    and you may want to change the order.

    so it is (or may be) easier to add things later.

    ----------- i can think of putting extra final ; for the same reason.
    That may not be such a good idea.  Writing multiple statements on one
    line is generally discouraged (notwithstanding that IMO it is
    occasionally appropriate).

    Rob Cliffe

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Grant Edwards@21:1/5 to rbowman on Thu Feb 23 11:27:44 2023
    On 2023-02-23, rbowman <[email protected]> wrote:
    On Wed, 22 Feb 2023 18:25:00 -0800 (PST), Hen Hanna wrote:

    i sometimes put extra commas... as:

    [ 1, 2, 3, 4, ]

    so it is (or may be) easier to add things later.

    That can bite you with things like JSON that aren't very forgiving.

    Oh, how I hate that about JSON...

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From [email protected]@21:1/5 to rbowman on Thu Feb 23 15:56:54 2023
    Grant,

    I am not sure it is fair to blame JSON for a design choice.

    Use of commas can be done many ways in many contexts.

    One context is a sort of placeholder. Can you have a language where a
    function has multiple arguments and you can skip some as in:

    Func(a,b,c)
    Func(a, b,)
    Func(a,,)

    Or even
    Func(a,,c)

    The missing arguments in such a language may be viewed as some sort of NULL
    or take a default value as a possibility.

    So what if you have a language where a list or tuple or other data structure incorporates a similar idea when created or used. If I have a matrix and I
    want every entry in row 4, meaning all columns, can I ask for mat[4,] and it means something else than mat[4] which may return a vector instead of a
    matrix?

    There are tons of such ideas that are choices. Python allows a SINGLE comma here but multiple are an error:

    a=1
    a
    1
    a=1,
    a
    (1,)
    a=1,,
    SyntaxError: incomplete input

    So why not allow MULTIPLE commas and ignore them? It is a choice!

    Here is a scenario where a trailing comma is an error:

    a,b,,, = range(5)
    SyntaxError: invalid syntax
    a,b,_,_,_ = range(5)
    a,b,*_ = range(5)

    The way to deal here with more items is to use * in front of the last one to gather any strays.

    But as _ is simply reused in the middle example and meant to be ignored, why
    do you need it if you would simply allow multiple commas? Short answer is
    they did not choose to design it that way. The places in python that do
    allow a trailing "," will allow only one. Beyond that, they assume you are making an error. So if someone wants to make a list of 5 things in
    alphabetical order but forgets a few, they cannot write:

    mylist = [first, , third, , , ]

    and then let the code run to be enhanced later with their reminder. What
    they can do is write this:

    mylist = [first,
    #,
    third,
    #,
    #,
    ]

    The reminders are now simply well-placed comments.

    Now we could debate the design of JSON and some enhancements people have
    made for other more portable data structures. I think it reasonable that
    they decided to stick to working with fully-formatted data structures and
    guess what? If I make a list or tuple or other data structures in python
    with a trailing comma, it is NOT stored that way and if you display it,
    there is no trailing comma shown. It is fully JSON compatible in some sense:

    import json
    mynest = [1,2, [3, 4,], 5,]
    mynest
    [1, 2, [3, 4], 5]
    json.dumps(mynest)
    '[1, 2, [3, 4], 5]'
    json.dumps([1,2, [3, 4,], 5,])
    '[1, 2, [3, 4], 5]'
    json.loads(json.dumps(mynest))
    [1, 2, [3, 4], 5]

    So when are you running into problems? Is it when reading something from a
    file using a function expecting properly formatted JSON?





    -----Original Message-----
    From: Python-list <python-list-bounces+avi.e.gross=[email protected]> On Behalf Of Grant Edwards
    Sent: Thursday, February 23, 2023 2:28 PM
    To: [email protected]
    Subject: Re: semi colonic

    On 2023-02-23, rbowman <[email protected]> wrote:
    On Wed, 22 Feb 2023 18:25:00 -0800 (PST), Hen Hanna wrote:

    i sometimes put extra commas... as:

    [ 1, 2, 3, 4, ]

    so it is (or may be) easier to add things later.

    That can bite you with things like JSON that aren't very forgiving.

    Oh, how I hate that about JSON...


    --
    https://mail.python.org/mailman/listinfo/python-list

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From [email protected]@21:1/5 to Hen Hanna on Thu Feb 23 15:26:53 2023
    Rob,

    It depends. Some purists say python abhors one liners. Well, I politely disagree and I enjoyed this book which shows how to write some quite compressed one-liners or nearly so.

    Python One-Liners: Write Concise, Eloquent Python Like a Professional Illustrated Edition
    by Christian Mayer (Author)

    https://www.amazon.com/Python-One-Liners-Concise-Eloquent-Professional/dp/1718500505/ref=sr_1_1?crid=2MMIRHGLR3GHN&keywords=python+one+liners&qid=1677183160&sprefix=python+one+liner%2Caps%2C93&sr=8-1

    The reality is that python is chock full of constructs that make one-liners easy and perhaps make a need for semi-colons less crucial.

    An example is a comprehension like:

    [x*y for x in range(10) for y in range(10) if x != y ]
    [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 3, 4, 5, 6, 7, 8, 9, 0, 2, 6, 8, 10, 12, 14, 16, 18, 0, 3, 6, 12, 15, 18, 21, 24, 27, 0, 4, 8, 12, 20, 24, 28, 32, 36, 0, 5, 10, 15, 20, 30, 35, 40, 45, 0, 6, 12, 18, 24, 30, 42, 48, 54, 0, 7, 14, 21, 28, 35, 42, 56, 63,
    0, 8, 16, 24, 32, 40, 48, 56, 72, 0, 9, 18, 27, 36, 45, 54, 63, 72]

    How many lines of code would it take to make than nonsense using an initializer for an empty list and nested loops and an "if" statement?

    A barely longer one-liner add more functionality with no added lines or semicolons:

    [(x*y, x+y, x>=y) for x in range(10) for y in range(10) if x != y ]
    [(0, 1, False), (0, 2, False), ..., (72, 17, True)]

    Examples of all kinds of such things about including seemingly trivial things like how a "with" statement lets you hide lots of code to do when entering and exiting use of an object. I have earlier mentioned the way packing and unpacking can effectively
    replace many lines of code with one.

    So the pythonic way often is not so much to do things one many lines but often to do things in a way that a unit of logic often can fit on one screen by using what the language offers judiciously even if you do not put multiple statement with semicolons
    on one line.

    -----Original Message-----
    From: Python-list <python-list-bounces+avi.e.gross=[email protected]> On Behalf Of Rob Cliffe via Python-list
    Sent: Thursday, February 23, 2023 6:08 AM
    To: [email protected]
    Subject: Re: semi colonic



    On 23/02/2023 02:25, Hen Hanna wrote:

    i sometimes put extra commas... as:

    [ 1, 2, 3, 4, ]
    That is a good idea.
    Even more so when the items are on separate lines:
    [
    "spam",
    "eggs",
    "cheese",
    ]
    and you may want to change the order.

    so it is (or may be) easier to add things later.

    ----------- i can think of putting extra final ; for the same reason.
    That may not be such a good idea. Writing multiple statements on one line is generally discouraged (notwithstanding that IMO it is occasionally appropriate).

    Rob Cliffe
    --
    https://mail.python.org/mailman/listinfo/python-list

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Chris Angelico@21:1/5 to Grant Edwards on Fri Feb 24 09:40:03 2023
    On Fri, 24 Feb 2023 at 06:29, Grant Edwards <[email protected]> wrote:

    On 2023-02-23, rbowman <[email protected]> wrote:
    On Wed, 22 Feb 2023 18:25:00 -0800 (PST), Hen Hanna wrote:

    i sometimes put extra commas... as:

    [ 1, 2, 3, 4, ]

    so it is (or may be) easier to add things later.

    That can bite you with things like JSON that aren't very forgiving.

    Oh, how I hate that about JSON...


    Also C#, it's incredibly frustrating that I'm not allowed to have a
    trailing comma in a function's argument list. Ugh. Completely
    unnecessary restriction.

    ChrisA

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Chris Angelico@21:1/5 to [email protected] on Fri Feb 24 17:40:15 2023
    On Fri, 24 Feb 2023 at 17:36, Greg Ewing via Python-list <[email protected]> wrote:

    On 24/02/23 9:26 am, [email protected] wrote:
    Python One-Liners: Write Concise, Eloquent Python Like a Professional Illustrated Edition
    by Christian Mayer (Author)

    I didn't know there were any Professional Illustrated Editions
    writing Pythom. You learn something every day! :-)


    "I don't want to be a moving picture in a book!" -- Bert, locomotive
    on the Small Railway

    ChrisA

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Greg Ewing@21:1/5 to [email protected] on Fri Feb 24 19:30:43 2023
    On 24/02/23 9:26 am, [email protected] wrote:
    Python One-Liners: Write Concise, Eloquent Python Like a Professional Illustrated Edition
    by Christian Mayer (Author)

    I didn't know there were any Professional Illustrated Editions
    writing Pythom. You learn something every day! :-)

    --
    Greg

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Peter J. Holzer@21:1/5 to [email protected] on Fri Feb 24 15:02:21 2023
    On 2023-02-23 15:56:54 -0500, [email protected] wrote:
    I am not sure it is fair to blame JSON for a design choice.

    We can't blame JSON (it has no agency), but as you say, it it was a
    choice. And we can absolutely blame Doug for making that choice!

    hp

    --
    _ | Peter J. Holzer | Story must make more sense than reality.
    |_|_) | |
    | | | [email protected] | -- Charles Stross, "Creative writing
    __/ | http://www.hjp.at/ | challenge!"

    -----BEGIN PGP SIGNATURE-----

    iQIzBAABCgAdFiEETtJbRjyPwVTYGJ5k8g5IURL+KF0FAmP4w2IACgkQ8g5IURL+ KF189A//ZDnWNHVURIsziXS/ShTKrxPx8ngWzESUA2BBjnAOK9QFBMYF0svLbKEK hkXYfk/H7LPOFQIZpHZ6yfjPcHOyoq621TbdIxGzMfruvEatwhilxu10YSe0Xv+w oD/Re6zThN4zl79MsPrsjJ/zJtYNckJR4o+trGoEXslIekSp7n0ixEVgX3xNmfHC FOwWU7bZNxkV1O3nK4PglS+DnoqT3QkEELgZ7dAYsDsJvNj5p5pFKGjElSrVCdL0 K7uQNOrpW4K7doSxkZZZIETkovWntBmDPNKfDgwRfXD3gcZKRdWKx9BKzmC3b2R+ Z96ADx1kJ2LAd2/G2pYC/E3TbZ/Hg1+WpilpF2X2xa6aWjHsK8qLbzNYmrV5RwbL cOpP9bake1NHE4aPpKoqjjELAiwQp+G3lj5UlfWmr9xPH71KCyAYPxfdngcf28Ci LFHF+GkmGUBpJjAb3tFaAUoZ2+tcbv677IqFvFFhA/GaOd4wzCXjjai3DngvFZMd jbanmYI5B4Z2NIYfrJkAkppZly2RiGlFYTwrH5zeEQLsvXDQcUbAY7I44h0tw6cH Ftgwg+eiCosmmmGdNSEP0ACXReMOTfJHwu8u0CcsMpeNq4E/9hci+ehQ4vJT2ZAf QHcR+cIxWIAIkZdPgKH35/zvi9ntxdu60LxPCr7