semi colonic

Thomas Passin list1 at tompassin.net
Wed Feb 22 23:26:19 EST 2023


On 2/22/2023 10:42 PM, avi.e.gross at gmail.com 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=gmail.com at python.org> On
> Behalf Of Thomas Passin
> Sent: Wednesday, February 22, 2023 9:05 PM
> To: python-list at python.org
> Subject: Re: semi colonic
> 
> On 2/22/2023 7:58 PM, avi.e.gross at gmail.com 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=gmail.com at python.org> On Behalf Of
>> Thomas Passin
>> Sent: Wednesday, February 22, 2023 7:24 PM
>> To: python-list at python.org
>> 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
> 



More information about the Python-list mailing list