semi colonic
Thomas Passin
list1 at tompassin.net
Wed Feb 22 21:04:45 EST 2023
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
>
More information about the Python-list
mailing list