(5,)a = 5,
a
... 6a = 5, \
(5, 6)a
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 ; ?
black_magic('a')
def f(a):
print(black_magic(a)) # or
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 ---etc.
------- CBR, CBV, CBN, (call by value), (call by name)....
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?
(5,)a = 5,
a
... 6a = 5, \
(5, 6)a
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.
black_magic('a')
def f(a):
print(black_magic(a)) # or
etc.
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)....
--
https://mail.python.org/mailman/listinfo/python-list
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.
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
import sys
print('\n'.join(sys.path))
!
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 waycurly brace.
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
Python mainly has a concept of indentation and blank lines as one partwrote:
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?
(5,)a = 5,
a
... 6a = 5, \
(5, 6)a
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
name)....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.
black_magic('a')
def f(a):
print(black_magic(a)) # or
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
etc.
--
https://mail.python.org/mailman/listinfo/python-list
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 waycurly brace.
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
wrote:
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?
(5,)a = 5,
a
... 6a = 5, \
(5, 6)a
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
name)....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. >>
black_magic('a')
def f(a):
print(black_magic(a)) # or
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
etc.
--
https://mail.python.org/mailman/listinfo/python-list
--
https://mail.python.org/mailman/listinfo/python-list
i sometimes put extra commas... as:
[ 1, 2, 3, 4, ]
so it is (or may be) easier to add things later.
Would anything serious break if it was deprecated for use as a statement terminator?
Would anything serious break if it was deprecated for use as a
statement terminator?
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))
So can anyone point to places in Python where a semicolon is part of a best or even good way to do anything?
So can anyone point to places in Python where a semicolon is part of a
best or even good way to do anything?
i sometimes put extra commas... as:That is a good idea.
[ 1, 2, 3, 4, ]
so it is (or may be) easier to add things later.That may not be such a good idea. Writing multiple statements on one
----------- i can think of putting extra final ; for the same reason.
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.
1a=1
a
(1,)a=1,
a
SyntaxError: incomplete inputa=1,,
SyntaxError: invalid syntaxa,b,,, = range(5)
a,b,_,_,_ = range(5)
a,b,*_ = range(5)
[1, 2, [3, 4], 5]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))
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.
i sometimes put extra commas... as:That is a good idea.
[ 1, 2, 3, 4, ]
so it is (or may be) easier to add things later.That may not be such a good idea. Writing multiple statements on one line is generally discouraged (notwithstanding that IMO it is occasionally appropriate).
----------- i can think of putting extra final ; for the same reason.
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...
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! :-)
Python One-Liners: Write Concise, Eloquent Python Like a Professional Illustrated Edition
by Christian Mayer (Author)
I am not sure it is fair to blame JSON for a design choice.
| Sysop: | Keyop |
|---|---|
| Location: | Huddersfield, West Yorkshire, UK |
| Users: | 714 |
| Nodes: | 16 (2 / 14) |
| Uptime: | 137:32:09 |
| Calls: | 12,087 |
| Files: | 14,997 |
| Messages: | 6,517,389 |