Rocksolid Light

News from da outaworlds

mail  files  register  groups  login

Message-ID:  

BOFH excuse #293: You must've hit the wrong any key.


comp / comp.lang.python / Re: Two aces up Python's sleeve

SubjectAuthor
* Two aces up Python's sleeveStefan Ram
`* Re: Two aces up Python's sleeveMild Shock
 `* Re: Two aces up Python's sleeveAnnada Behera
  +- Re: Two aces up Python's sleeveStefan Ram
  +* Re: Two aces up Python's sleeveMild Shock
  |`* Re: Two aces up Python's sleeveGreg Ewing
  | +- Re: Two aces up Python's sleevedn
  | `* Re: Two aces up Python's sleeveMild Shock
  |  `* Re: Two aces up Python's sleeveMild Shock
  |   `- Re: Two aces up Python's sleeveMild Shock
  `* Re: Two aces up Python's sleeve (Posting On Python-List Prohibited)Lawrence D'Oliveiro
   `* Re: Two aces up Python's sleeve (Posting On Python-List Prohibited)Mild Shock
    +* Re: Two aces up Python's sleeve (Posting On Python-List Prohibited)dn
    |`- Re: Two aces up Python's sleeve (Posting On Python-List Prohibited)Mild Shock
    `- Re: Two aces up Python's sleeve (Posting On Python-List Prohibited)Thomas Passin

1
Subject: Two aces up Python's sleeve
From: Stefan Ram
Newsgroups: comp.lang.python
Organization: Stefan Ram
Date: Wed, 6 Nov 2024 00:49 UTC
Path: eternal-september.org!news.eternal-september.org!feeder2.eternal-september.org!fu-berlin.de!uni-berlin.de!not-for-mail
From: ram@zedat.fu-berlin.de (Stefan Ram)
Newsgroups: comp.lang.python
Subject: Two aces up Python's sleeve
Date: 6 Nov 2024 00:49:15 GMT
Organization: Stefan Ram
Lines: 21
Expires: 1 Jul 2025 11:59:58 GMT
Message-ID: <seven-20241106014329@ram.dialup.fu-berlin.de>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-Trace: news.uni-berlin.de POyAEnTvoH5G4N7zBc/ejAZ8fwaOd6P2EVGaIiZeCL9h6e
Cancel-Lock: sha1:MatEFTf9yJ4tJ1Z0oFsEGwHh0Sc= sha256:osf+WcvO2VT2y5zd9kVxmK2+SQ9BIXiezl9scfKYfv8=
X-Copyright: (C) Copyright 2024 Stefan Ram. All rights reserved.
Distribution through any means other than regular usenet
channels is forbidden. It is forbidden to publish this
article in the Web, to change URIs of this article into links,
and to transfer the body without this notice, but quotations
of parts in other Usenet posts are allowed.
X-No-Archive: Yes
Archive: no
X-No-Archive-Readme: "X-No-Archive" is set, because this prevents some
services to mirror the article in the web. But the article may
be kept on a Usenet archive server with only NNTP access.
X-No-Html: yes
Content-Language: en-US
View all headers

ram@zedat.fu-berlin.de (Stefan Ram) wrote or quoted:
>last_item = my_list[ -1 ]
>Way cleaner than my_list[ len( my_list )- 1 ], don't you think?

In "The Mental Game of Python," Raymond Hettinger spills the
beans about our noggins only being able to juggle 7 +/- 2
things in our short-term memory.

So, "last_item = my_list[ -1 ]" might still make the cut,
while "my_list[ len( my_list)- 1 ]" could be biting off
more than we can chew.

|The problem is, the number of brain registers this uses is
|10. This is no longer a decryption effort. This is a puzzle.
|At the moment you put it together, you fully understand it.
|But if this is embedded in bigger code, every time you hit
|this line, you're going to have to pick apart "what does this
|thing do?".
Raymond Hettinger

Subject: Re: Two aces up Python's sleeve
From: Mild Shock
Newsgroups: comp.lang.python
Date: Wed, 6 Nov 2024 16:27 UTC
References: 1
Path: eternal-september.org!news.eternal-september.org!feeder2.eternal-september.org!weretis.net!feeder8.news.weretis.net!reader5.news.weretis.net!news.solani.org!.POSTED!not-for-mail
From: janburse@fastmail.fm (Mild Shock)
Newsgroups: comp.lang.python
Subject: Re: Two aces up Python's sleeve
Date: Wed, 6 Nov 2024 17:27:37 +0100
Message-ID: <vgg5dn$ij48$1@solani.org>
References: <seven-20241106014329@ram.dialup.fu-berlin.de>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Wed, 6 Nov 2024 16:27:35 -0000 (UTC)
Injection-Info: solani.org;
logging-data="609416"; mail-complaints-to="abuse@news.solani.org"
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Firefox/91.0 SeaMonkey/2.53.19
Cancel-Lock: sha1:M03Vtyt4+5BpqZEdwsaU730doy8=
In-Reply-To: <seven-20241106014329@ram.dialup.fu-berlin.de>
X-User-ID: eJwNysEBwCAIA8CVEEiQcaiU/UfQ9x2MiyecoGMwVC3iyBnZ2rHYTatPGvm/oNHtCE+ley2bytwm8OdZaXUBP+oUsA==
View all headers

Then please explain why I have to write:

i += 1

Instead of the shorter:

i ++

My short-term memory is really stressed.

Stefan Ram schrieb:
> ram@zedat.fu-berlin.de (Stefan Ram) wrote or quoted:
>> last_item = my_list[ -1 ]
>> Way cleaner than my_list[ len( my_list )- 1 ], don't you think?
>
> In "The Mental Game of Python," Raymond Hettinger spills the
> beans about our noggins only being able to juggle 7 +/- 2
> things in our short-term memory.
>
> So, "last_item = my_list[ -1 ]" might still make the cut,
> while "my_list[ len( my_list)- 1 ]" could be biting off
> more than we can chew.
>
> |The problem is, the number of brain registers this uses is
> |10. This is no longer a decryption effort. This is a puzzle.
> |At the moment you put it together, you fully understand it.
> |But if this is embedded in bigger code, every time you hit
> |this line, you're going to have to pick apart "what does this
> |thing do?".
> Raymond Hettinger
>
>

Subject: Re: Two aces up Python's sleeve
From: Annada Behera
Newsgroups: comp.lang.python
Organization: tilde.green
Date: Thu, 7 Nov 2024 07:25 UTC
References: 1 2
Path: eternal-september.org!news.eternal-september.org!feeder2.eternal-september.org!news.quux.org!tilde.green!.POSTED.103.160.128.32!not-for-mail
From: annada@tilde.green (Annada Behera)
Newsgroups: comp.lang.python
Subject: Re: Two aces up Python's sleeve
Date: Thu, 07 Nov 2024 12:55:53 +0530
Organization: tilde.green
Sender: annada@tilde.green
Message-ID: <050c2ce9efd8442fb902ecc926afb1ee42fe6c34.camel@tilde.green>
References: <seven-20241106014329@ram.dialup.fu-berlin.de>
<vgg5dn$ij48$1@solani.org>
MIME-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Injection-Info: tilde.green; posting-account="annada@tilde.green"; posting-host="103.160.128.32";
logging-data="1167743"; mail-complaints-to="admins@tilde.green"
User-Agent: Evolution 3.52.2
In-Reply-To: <vgg5dn$ij48$1@solani.org>
View all headers

>Then please explain why I have to write:
>
>    i += 1
>
>Instead of the shorter:
>
>    i ++
>
>My short-term memory is really stressed.

I heard this behavior is because python's integers are immutable.
For example:

>>> x,y = 5,5
>>> id(x) == id(y)
True

5 is a object that x and y points to. ++x or x++ will redefine 5 to
6, which the interpreter forbids to keep it's state mathematically
consistent. Also, by not supporting x++ and ++x, it avoids the pre-
and post-increment (substitute-increment v. increment-substitute) bugs
that plagues C and it's children.

Subject: Re: Two aces up Python's sleeve
From: Stefan Ram
Newsgroups: comp.lang.python
Organization: Stefan Ram
Date: Thu, 7 Nov 2024 11:03 UTC
References: 1 2 3
Path: eternal-september.org!news.eternal-september.org!feeder2.eternal-september.org!fu-berlin.de!uni-berlin.de!not-for-mail
From: ram@zedat.fu-berlin.de (Stefan Ram)
Newsgroups: comp.lang.python
Subject: Re: Two aces up Python's sleeve
Date: 7 Nov 2024 11:03:29 GMT
Organization: Stefan Ram
Lines: 7
Expires: 1 Jul 2025 11:59:58 GMT
Message-ID: <logic-20241107120231@ram.dialup.fu-berlin.de>
References: <seven-20241106014329@ram.dialup.fu-berlin.de> <vgg5dn$ij48$1@solani.org> <050c2ce9efd8442fb902ecc926afb1ee42fe6c34.camel@tilde.green>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-Trace: news.uni-berlin.de EGoKEIFSX/q/TPFXGz1Pug7Ffsczg/SmC1XStPxSJFoTdY
Cancel-Lock: sha1:bhl8Ha7zJ4s79VdT4NuhPV6IuqI= sha256:XAKfVR+f8+qAm/jmU9a68JclLPNOviAPoS5fClceCE0=
X-Copyright: (C) Copyright 2024 Stefan Ram. All rights reserved.
Distribution through any means other than regular usenet
channels is forbidden. It is forbidden to publish this
article in the Web, to change URIs of this article into links,
and to transfer the body without this notice, but quotations
of parts in other Usenet posts are allowed.
X-No-Archive: Yes
Archive: no
X-No-Archive-Readme: "X-No-Archive" is set, because this prevents some
services to mirror the article in the web. But the article may
be kept on a Usenet archive server with only NNTP access.
X-No-Html: yes
Content-Language: en-US
View all headers

Annada Behera <annada@tilde.green> wrote or quoted:
>5 is a object that x and y points to. ++x or x++ will redefine 5 to

This doesn't add up for me. Using the same "logic,"
you might as well say "x = x + 1" is off limits.

Subject: Re: Two aces up Python's sleeve
From: Mild Shock
Newsgroups: comp.lang.python
Date: Thu, 7 Nov 2024 14:04 UTC
References: 1 2 3
Path: eternal-september.org!news.eternal-september.org!feeder2.eternal-september.org!2.eu.feeder.erje.net!3.eu.feeder.erje.net!feeder.erje.net!usenet.goja.nl.eu.org!weretis.net!feeder8.news.weretis.net!reader5.news.weretis.net!news.solani.org!.POSTED!not-for-mail
From: janburse@fastmail.fm (Mild Shock)
Newsgroups: comp.lang.python
Subject: Re: Two aces up Python's sleeve
Date: Thu, 7 Nov 2024 15:04:53 +0100
Message-ID: <vgihe5$9tsc$1@solani.org>
References: <seven-20241106014329@ram.dialup.fu-berlin.de>
<vgg5dn$ij48$1@solani.org>
<050c2ce9efd8442fb902ecc926afb1ee42fe6c34.camel@tilde.green>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Thu, 7 Nov 2024 14:04:53 -0000 (UTC)
Injection-Info: solani.org;
logging-data="325516"; mail-complaints-to="abuse@news.solani.org"
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Firefox/91.0 SeaMonkey/2.53.19
Cancel-Lock: sha1:jv7a+MEWoYopsP2V4p29tK/6DHk=
In-Reply-To: <050c2ce9efd8442fb902ecc926afb1ee42fe6c34.camel@tilde.green>
X-User-ID: eJwNxcEBwCAIA8CVVCAx4yCW/Uew97kwTBQdAY+ORv3RYruGCqbiWRdiZIDTy2V7KPNaw6WF5VRb6TvszAckCRSm
View all headers

This only works for small integers. I guess
this is because tagged pointers are used
nowadays ? For large integers, also known

as bigint, it doesn't work:

Python 3.13.0a1 (tags/v3.13.0a1:ad056f0, Oct 13 2023, 09:51:17)

>>> x, y = 5, 4+1
>>> id(x) == id(y)
True

>>> x, y = 10**200, 10**199*10
>>> x == y
True
>>> id(x) == id(y)
False

In tagged pointers a small integer is
directly inlined into the pointer. The
pointer has usually some higher bits,

that identify the type and when masking
to see the lower bits, one gets the
integer value.

But I don't know for sure whats going on,
would need to find a CPython documentation.

P.S.: I also tested PyPy it doesn't show
the same behaviour, because it computes
an exaberated id():

Python 3.10.14 (39dc8d3c85a7, Aug 27 2024, 14:33:33)
[PyPy 7.3.17 with MSC v.1929 64 bit (AMD64)]
>>>> x, y = 5, 4+1
>>>> id(x) == id(y)
True

>>>> x, y = 10**200, 10**199*10
>>>> id(x) == id(y)
True
>>>> id(x)
1600000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000
000000000000000001

Quite funny!

Annada Behera schrieb:
>> Then please explain why I have to write:
>>
>>     i += 1
>>
>> Instead of the shorter:
>>
>>     i ++
>>
>> My short-term memory is really stressed.
>
> I heard this behavior is because python's integers are immutable.
> For example:
>
> >>> x,y = 5,5
> >>> id(x) == id(y)
> True
>
> 5 is a object that x and y points to. ++x or x++ will redefine 5 to
> 6, which the interpreter forbids to keep it's state mathematically
> consistent. Also, by not supporting x++ and ++x, it avoids the pre-
> and post-increment (substitute-increment v. increment-substitute) bugs
> that plagues C and it's children.
>
>

Subject: Re: Two aces up Python's sleeve
From: Greg Ewing
Newsgroups: comp.lang.python
Date: Thu, 7 Nov 2024 22:15 UTC
References: 1 2 3 4
Path: eternal-september.org!news.eternal-september.org!feeder2.eternal-september.org!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: greg.ewing@canterbury.ac.nz (Greg Ewing)
Newsgroups: comp.lang.python
Subject: Re: Two aces up Python's sleeve
Date: Fri, 8 Nov 2024 11:15:38 +1300
Lines: 15
Message-ID: <lp4sgdFg90oU1@mid.individual.net>
References: <seven-20241106014329@ram.dialup.fu-berlin.de>
<vgg5dn$ij48$1@solani.org>
<050c2ce9efd8442fb902ecc926afb1ee42fe6c34.camel@tilde.green>
<vgihe5$9tsc$1@solani.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
X-Trace: individual.net uwv6TRVnUDRHYL6EUJsluA7FDmBk3qlDGNAKOmsYuW7COZTzZy
Cancel-Lock: sha1:9Oxf8Yi4R6v5W9m1deeUfmT4R+I= sha256:LYD6inCH5XdE9mNRJKi20wDqfY+EEotiBDTt5XW8bsU=
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:91.0)
Gecko/20100101 Thunderbird/91.3.2
Content-Language: en-US
In-Reply-To: <vgihe5$9tsc$1@solani.org>
View all headers

On 8/11/24 3:04 am, Mild Shock wrote:
> This only works for small integers. I guess
> this is because tagged pointers are used
> nowadays ?

No, it's because integers in a certain small range are cached. Not sure
what the actual range is nowadays, it used to be something like -5 to
256 I think.

BTW you have to be careful testing this, because the compiler sometimes
does constant folding, so you need to be sure it's actually computing
the numbers at run time.

--
Greg

Subject: Re: Two aces up Python's sleeve
From: dn
Newsgroups: comp.lang.python
Organization: DWM
Date: Fri, 8 Nov 2024 00:07 UTC
References: 1 2 3 4 5 6
Path: eternal-september.org!news.eternal-september.org!feeder2.eternal-september.org!fu-berlin.de!uni-berlin.de!not-for-mail
From: PythonList@DancesWithMice.info (dn)
Newsgroups: comp.lang.python
Subject: Re: Two aces up Python's sleeve
Date: Fri, 8 Nov 2024 13:07:48 +1300
Organization: DWM
Lines: 61
Message-ID: <mailman.87.1731024481.4695.python-list@python.org>
References: <seven-20241106014329@ram.dialup.fu-berlin.de>
<vgg5dn$ij48$1@solani.org>
<050c2ce9efd8442fb902ecc926afb1ee42fe6c34.camel@tilde.green>
<vgihe5$9tsc$1@solani.org> <lp4sgdFg90oU1@mid.individual.net>
<0c94311a-f3e4-4aac-93e8-9bf95c065dcf@DancesWithMice.info>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: news.uni-berlin.de z00KZoEboE6Apow70GFSCQ2upNZeyq0zTLQ9vktz60FQ==
Cancel-Lock: sha1:o+QCNzq1XyldtWeWKNTkL96Skes= sha256:qtz2CmbeO/WmkMCr/q5aTeJOh2pEC15nrG+CbWbw/3o=
Return-Path: <PythonList@DancesWithMice.info>
X-Original-To: python-list@python.org
Delivered-To: python-list@mail.python.org
Authentication-Results: mail.python.org; dkim=pass
reason="2048-bit key; unprotected key"
header.d=danceswithmice.info header.i=@danceswithmice.info
header.b=enOUZecE; dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.002
X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; '=dn': 0.09; 'compiler':
0.09; 'computing': 0.09; 'from:addr:danceswithmice.info': 0.09;
'from:addr:pythonlist': 0.09; 'hat': 0.09; 'linux': 0.09;
'newsgroup': 0.09; 'shock': 0.09; 'subject:Python': 0.12;
'constant': 0.16; 'forever.': 0.16; 'greg': 0.16; 'indeed': 0.16;
'integer': 0.16; 'message-id:@DancesWithMice.info': 0.16;
'pointers': 0.16; 'print(': 0.16; 'received:51.254': 0.16;
'received:51.254.211': 0.16; 'received:51.254.211.219': 0.16;
'received:cloud': 0.16; 'received:rangi.cloud': 0.16; 'think.':
0.16; 'wrote:': 0.16; 'python': 0.16; 'to:addr:python-list': 0.20;
'run': 0.23; 'actual': 0.25; 'else': 0.27; '>>>': 0.28; 'header
:User-Agent:1': 0.30; 'am,': 0.31; '254': 0.32; 'guess': 0.32;
'python-list': 0.32; 'header:Organization:1': 0.32; 'hold': 0.33;
'header:In-Reply-To:1': 0.34; "it's": 0.37; 'could': 0.37;
'received:192.168': 0.37; 'url-ip:151.101.0.223/32': 0.38; 'url-
ip:151.101.128.223/32': 0.38; 'url-ip:151.101.192.223/32': 0.38;
'url-ip:151.101.64.223/32': 0.38; 'this,': 0.39; 'valid': 0.39;
'decide': 0.39; 'forwarding': 0.40; 'something': 0.40; 'seen':
0.62; 'skip:i 20': 0.62; 'range': 0.64; 'received:51': 0.64;
'thus': 0.64; 'time.': 0.66; 'numbers': 0.67; 'guaranteed': 0.67;
'1000': 0.70; '....': 0.76; 'btw': 0.84
DKIM-Filter: OpenDKIM Filter v2.11.0 vps.rangi.cloud 3540A7FF5
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=danceswithmice.info;
s=staff; t=1731024472;
bh=1Ike7doebtO7zHIF4pkbc1GfRuaq5lI6T2O6bL3gkm0=;
h=Date:From:Subject:To:References:In-Reply-To:From;
b=enOUZecEDZ/yf9W3ZUI/2TePxyX2uQq19JDahEgC9l60X4Q4mRuQ042o/EgnddkEq
ISSoso28bIkadTqnUZ6mjUcGXYoe6kXvDZsaYTB4jfaRkprmAakXbGvAxRnVLMWhCA
jSWuHUTbIReQ1IWX0E9i70MSLeBEISGis+wnRyrU4ocjqXLlMNC37C4ETOaQexjhyo
X8m5n8RRkH3VeQZM2GT/jEBuiRrLF3OkzO5k0L7WxhqFD9Dg3RaDyN7cOjuwyKBSZ1
BcpMZAySv5eVd1JjLK3DbxKPXcDgC7K8xqSv/5anH7UqvGMSgF/8rcnCewOl6iZz+K
Z+lwIWANGWKVQ==
User-Agent: Mozilla Thunderbird
Content-Language: en-US
In-Reply-To: <lp4sgdFg90oU1@mid.individual.net>
X-BeenThere: python-list@python.org
X-Mailman-Version: 2.1.39
Precedence: list
List-Id: General discussion list for the Python programming language
<python-list.python.org>
List-Unsubscribe: <https://mail.python.org/mailman/options/python-list>,
<mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive: <https://mail.python.org/pipermail/python-list/>
List-Post: <mailto:python-list@python.org>
List-Help: <mailto:python-list-request@python.org?subject=help>
List-Subscribe: <https://mail.python.org/mailman/listinfo/python-list>,
<mailto:python-list-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID: <0c94311a-f3e4-4aac-93e8-9bf95c065dcf@DancesWithMice.info>
X-Mailman-Original-References: <seven-20241106014329@ram.dialup.fu-berlin.de>
<vgg5dn$ij48$1@solani.org>
<050c2ce9efd8442fb902ecc926afb1ee42fe6c34.camel@tilde.green>
<vgihe5$9tsc$1@solani.org> <lp4sgdFg90oU1@mid.individual.net>
View all headers

On 8/11/24 11:15, Greg Ewing via Python-list wrote:
> On 8/11/24 3:04 am, Mild Shock wrote:
>> This only works for small integers. I guess
>> this is because tagged pointers are used
>> nowadays ?
>
> No, it's because integers in a certain small range are cached. Not sure
> what the actual range is nowadays, it used to be something like -5 to
> 256 I think.
>
> BTW you have to be careful testing this, because the compiler sometimes
> does constant folding, so you need to be sure it's actually computing
> the numbers at run time.

Haven't seen the OP. Is the Newsgroup link forwarding to the email-list
correctly?

Integer interning is indeed valid for -5 <= i <= 256
("it works on my machine"! see below)

>>> a = 0; b = 0; c = 0; d = 0
>>> while a is b:
.... print( a, b, end=" ", )
.... print( c, d, ) if c is d else print()
.... a += 1; b += 1; c -= 1; d -= 1
....
0 0 0 0
1 1 -1 -1
2 2 -2 -2
3 3 -3 -3
4 4 -4 -4
5 5 -5 -5
6 6
7 7
8 8
9 9
....
254 254
255 255
256 256
>>>

Be aware that this is implementation-dependent and not guaranteed to
hold forever.

dn  ~  python
Python 3.12.7 (main, Oct 1 2024, 00:00:00) [GCC 13.3.1 20240913 (Red
Hat 13.3.1-3)] on linux
Type "help", "copyright", "credits" or "license" for more information.

See also https://docs.python.org/3/library/sys.html#sys.intern

Thus could decide what is interned for yourself:

a_string = sys.intern( str( 1000 ) )

--
Regards,
=dn

Subject: Re: Two aces up Python's sleeve
From: Mild Shock
Newsgroups: comp.lang.python
Date: Fri, 8 Nov 2024 00:25 UTC
References: 1 2 3 4 5
Path: eternal-september.org!news.eternal-september.org!feeder2.eternal-september.org!weretis.net!feeder8.news.weretis.net!reader5.news.weretis.net!news.solani.org!.POSTED!not-for-mail
From: janburse@fastmail.fm (Mild Shock)
Newsgroups: comp.lang.python
Subject: Re: Two aces up Python's sleeve
Date: Fri, 8 Nov 2024 01:25:52 +0100
Message-ID: <vgjlqg$ki9n$1@solani.org>
References: <seven-20241106014329@ram.dialup.fu-berlin.de>
<vgg5dn$ij48$1@solani.org>
<050c2ce9efd8442fb902ecc926afb1ee42fe6c34.camel@tilde.green>
<vgihe5$9tsc$1@solani.org> <lp4sgdFg90oU1@mid.individual.net>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Fri, 8 Nov 2024 00:25:52 -0000 (UTC)
Injection-Info: solani.org;
logging-data="674103"; mail-complaints-to="abuse@news.solani.org"
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Firefox/91.0 SeaMonkey/2.53.19
Cancel-Lock: sha1:UQZT+LmAjpPPnaehEz8szqeUjL8=
X-User-ID: eJwFwQkBwDAIA0BLfAlMTgvUv4TdwansDIKBh7cdMmWKvl/xxDGu6OTndienqmlTW4aG028+vSKQrTXsyR9MTRU1
In-Reply-To: <lp4sgdFg90oU1@mid.individual.net>
View all headers

Hi,

In Java its possible to work this way
with the Integer datatype, just call
Integer.valueOf().

I am not sure whether CPython does the
same. Because it shows me the same behaviour
for small integers that are more than

only in the range -128 to 128. You can try yourself:

Python 3.14.0a1 (tags/v3.14.0a1:8cdaca8, Oct 15 2024, 20:08:21)
>>> x,y = 10**10, 10**9*10
>>> id(x) == id(y)
True

Maybe the idea that objects have an address
that can be accessed via id() has been abandoned.
This is already seen in PyPy. So maybe we

are falsly assuming that id() gives na object address.

Greg Ewing schrieb:
> On 8/11/24 3:04 am, Mild Shock wrote:
>> This only works for small integers. I guess
>> this is because tagged pointers are used
>> nowadays ?
>
> No, it's because integers in a certain small range are cached. Not sure
> what the actual range is nowadays, it used to be something like -5 to
> 256 I think.
>
> BTW you have to be careful testing this, because the compiler sometimes
> does constant folding, so you need to be sure it's actually computing
> the numbers at run time.
>

Subject: Re: Two aces up Python's sleeve
From: Mild Shock
Newsgroups: comp.lang.python
Date: Fri, 8 Nov 2024 00:29 UTC
References: 1 2 3 4 5 6
Path: eternal-september.org!news.eternal-september.org!feeder2.eternal-september.org!weretis.net!feeder8.news.weretis.net!reader5.news.weretis.net!news.solani.org!.POSTED!not-for-mail
From: janburse@fastmail.fm (Mild Shock)
Newsgroups: comp.lang.python
Subject: Re: Two aces up Python's sleeve
Date: Fri, 8 Nov 2024 01:29:48 +0100
Message-ID: <vgjm1s$ki9n$2@solani.org>
References: <seven-20241106014329@ram.dialup.fu-berlin.de>
<vgg5dn$ij48$1@solani.org>
<050c2ce9efd8442fb902ecc926afb1ee42fe6c34.camel@tilde.green>
<vgihe5$9tsc$1@solani.org> <lp4sgdFg90oU1@mid.individual.net>
<vgjlqg$ki9n$1@solani.org>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Fri, 8 Nov 2024 00:29:48 -0000 (UTC)
Injection-Info: solani.org;
logging-data="674103"; mail-complaints-to="abuse@news.solani.org"
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Firefox/91.0 SeaMonkey/2.53.19
Cancel-Lock: sha1:7JneXaYjmF8CoX/GdUWxJPiax4s=
In-Reply-To: <vgjlqg$ki9n$1@solani.org>
X-User-ID: eJwNyskBwCAIBMCWFrmkHES3/xKSeY9rSExaeJjTybMvz6znmN3I0eyz0KUlQlVllptx30LByMj7x3xsUCAfaGEVxQ==
View all headers

For example this article:

https://www.codementor.io/@arpitbhayani/python-caches-integers-16jih595jk

about the integer singletons claims:

>>> x, y = 257, 257
>>> id(x) == id(y)
False

But on Windows my recent CPython doesn't do that:

Python 3.14.0a1 (tags/v3.14.0a1:8cdaca8, Oct 15 2024, 20:08:21)
>>> x, y = 257, 257
>>> id(x) == id(y)
True

Mild Shock schrieb:
> Hi,
>
> In Java its possible to work this way
> with the Integer datatype, just call
> Integer.valueOf().
>
> I am not sure whether CPython does the
> same. Because it shows me the same behaviour
> for small integers that are more than
>
> only in the range -128 to 128. You can try yourself:
>
> Python 3.14.0a1 (tags/v3.14.0a1:8cdaca8, Oct 15 2024, 20:08:21)
> >>> x,y = 10**10, 10**9*10
> >>> id(x) == id(y)
> True
>
> Maybe the idea that objects have an address
> that can be accessed via id() has been abandoned.
> This is already seen in PyPy. So maybe we
>
> are falsly assuming that id() gives na object address.
>
> Greg Ewing schrieb:
>> On 8/11/24 3:04 am, Mild Shock wrote:
>>> This only works for small integers. I guess
>>> this is because tagged pointers are used
>>> nowadays ?
>>
>> No, it's because integers in a certain small range are cached. Not
>> sure what the actual range is nowadays, it used to be something like
>> -5 to 256 I think.
>>
>> BTW you have to be careful testing this, because the compiler
>> sometimes does constant folding, so you need to be sure it's actually
>> computing the numbers at run time.
>>
>

Subject: Re: Two aces up Python's sleeve
From: Mild Shock
Newsgroups: comp.lang.python
Date: Fri, 8 Nov 2024 00:47 UTC
References: 1 2 3 4 5 6 7
Path: eternal-september.org!news.eternal-september.org!feeder2.eternal-september.org!news.swapon.de!weretis.net!feeder8.news.weretis.net!reader5.news.weretis.net!news.solani.org!.POSTED!not-for-mail
From: janburse@fastmail.fm (Mild Shock)
Newsgroups: comp.lang.python
Subject: Re: Two aces up Python's sleeve
Date: Fri, 8 Nov 2024 01:47:14 +0100
Message-ID: <vgjn2h$kiom$1@solani.org>
References: <seven-20241106014329@ram.dialup.fu-berlin.de>
<vgg5dn$ij48$1@solani.org>
<050c2ce9efd8442fb902ecc926afb1ee42fe6c34.camel@tilde.green>
<vgihe5$9tsc$1@solani.org> <lp4sgdFg90oU1@mid.individual.net>
<vgjlqg$ki9n$1@solani.org> <vgjm1s$ki9n$2@solani.org>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Fri, 8 Nov 2024 00:47:13 -0000 (UTC)
Injection-Info: solani.org;
logging-data="674582"; mail-complaints-to="abuse@news.solani.org"
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Firefox/91.0 SeaMonkey/2.53.19
Cancel-Lock: sha1:lOA5c3If1M/hIErg/RKX7fcBoaM=
In-Reply-To: <vgjm1s$ki9n$2@solani.org>
X-User-ID: eJwFwYEBwCAIA7CXBCnQc5TZ/09Ygp2WU5HIgKAp+xjjpve8Pcycuput5fdcTjYfap29+mSnMJSY09WE4wdKxxT9
View all headers

The wiked brain of ChatGPT gives me a lead:

PEP 659
Storing data caches before the bytecode.

Maybe its an effect of constant folding
and constant pooling by the compiler?

Mild Shock schrieb:
>
> For example this article:
>
> https://www.codementor.io/@arpitbhayani/python-caches-integers-16jih595jk
>
> about the integer singletons claims:
>
> >>> x, y = 257, 257
> >>> id(x) == id(y)
> False
>
> But on Windows my recent CPython doesn't do that:
>
> Python 3.14.0a1 (tags/v3.14.0a1:8cdaca8, Oct 15 2024, 20:08:21)
> >>> x, y = 257, 257
> >>> id(x) == id(y)
> True
>
> Mild Shock schrieb:
>> Hi,
>>
>> In Java its possible to work this way
>> with the Integer datatype, just call
>> Integer.valueOf().
>>
>> I am not sure whether CPython does the
>> same. Because it shows me the same behaviour
>> for small integers that are more than
>>
>> only in the range -128 to 128. You can try yourself:
>>
>> Python 3.14.0a1 (tags/v3.14.0a1:8cdaca8, Oct 15 2024, 20:08:21)
>>  >>> x,y = 10**10, 10**9*10
>>  >>> id(x) == id(y)
>> True
>>
>> Maybe the idea that objects have an address
>> that can be accessed via id() has been abandoned.
>> This is already seen in PyPy. So maybe we
>>
>> are falsly assuming that id() gives na object address.
>>
>> Greg Ewing schrieb:
>>> On 8/11/24 3:04 am, Mild Shock wrote:
>>>> This only works for small integers. I guess
>>>> this is because tagged pointers are used
>>>> nowadays ?
>>>
>>> No, it's because integers in a certain small range are cached. Not
>>> sure what the actual range is nowadays, it used to be something like
>>> -5 to 256 I think.
>>>
>>> BTW you have to be careful testing this, because the compiler
>>> sometimes does constant folding, so you need to be sure it's actually
>>> computing the numbers at run time.
>>>
>>
>

Subject: Re: Two aces up Python's sleeve (Posting On Python-List Prohibited)
From: Lawrence D'Oliv
Newsgroups: comp.lang.python
Organization: A noiseless patient Spider
Date: Fri, 8 Nov 2024 01:10 UTC
References: 1 2 3
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: ldo@nz.invalid (Lawrence D'Oliveiro)
Newsgroups: comp.lang.python
Subject: Re: Two aces up Python's sleeve (Posting On Python-List Prohibited)
Date: Fri, 8 Nov 2024 01:10:34 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 11
Message-ID: <vgjoe9$2stii$2@dont-email.me>
References: <seven-20241106014329@ram.dialup.fu-berlin.de>
<vgg5dn$ij48$1@solani.org>
<050c2ce9efd8442fb902ecc926afb1ee42fe6c34.camel@tilde.green>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Fri, 08 Nov 2024 02:10:34 +0100 (CET)
Injection-Info: dont-email.me; posting-host="8804b559eebfef5f2e93c08a58445e57";
logging-data="3044946"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19RqnVMcjNGV5bGWB9Mu36Z"
User-Agent: Pan/0.160 (Toresk; )
Cancel-Lock: sha1:XHAYUMaTMR5OMp32mbdBhOas0No=
View all headers

On Thu, 07 Nov 2024 12:55:53 +0530, Annada Behera wrote:

> I heard this behavior is because python's integers are immutable.

Nothing to do with that.

> ++x or x++ will redefine 5 to 6, which the interpreter forbids ...

One of those is actually syntactically valid.

It just won’t do what you expect it to do.

Subject: Re: Two aces up Python's sleeve (Posting On Python-List Prohibited)
From: Mild Shock
Newsgroups: comp.lang.python
Date: Fri, 8 Nov 2024 01:40 UTC
References: 1 2 3 4
Path: eternal-september.org!news.eternal-september.org!feeder2.eternal-september.org!weretis.net!feeder8.news.weretis.net!reader5.news.weretis.net!news.solani.org!.POSTED!not-for-mail
From: janburse@fastmail.fm (Mild Shock)
Newsgroups: comp.lang.python
Subject: Re: Two aces up Python's sleeve (Posting On Python-List Prohibited)
Date: Fri, 8 Nov 2024 02:40:56 +0100
Message-ID: <vgjq77$aj8c$1@solani.org>
References: <seven-20241106014329@ram.dialup.fu-berlin.de>
<vgg5dn$ij48$1@solani.org>
<050c2ce9efd8442fb902ecc926afb1ee42fe6c34.camel@tilde.green>
<vgjoe9$2stii$2@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Fri, 8 Nov 2024 01:40:55 -0000 (UTC)
Injection-Info: solani.org;
logging-data="347404"; mail-complaints-to="abuse@news.solani.org"
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Firefox/91.0 SeaMonkey/2.53.19
Cancel-Lock: sha1:BLstDVwn9CtsYSvj3izfL9G0BtM=
X-User-ID: eJwNxsEBwCAIA8CVGkhQxoGi+4/Q3uvkgXgXQ0FdXRTBLutjWg/obXh4Zmf/Tc7u6Z6BC1StCaybFSPbyuMfRVEVHw==
In-Reply-To: <vgjoe9$2stii$2@dont-email.me>
View all headers

Well you can use your Browser, since
JavaScript understand post and pre increment:

> x = 5
5 > x ++
5 > x = 5
5 > ++ x
6

So we have x ++ equals in Python:

x + = 1
x - 1

And ++ x equals in Python:

x += 1
x

But I don't know how to combine an
assignment and an expression into one
expession. In JavaScript one can use

the comma:

> x = 5
5 > y = (x += 1, x - 1)
5 > x = 5
5 > y = (x += 1, x)
6

But in Python the comma would create a tuple.

Lawrence D'Oliveiro schrieb:
> On Thu, 07 Nov 2024 12:55:53 +0530, Annada Behera wrote:
>
>> I heard this behavior is because python's integers are immutable.
>
> Nothing to do with that.
>
>> ++x or x++ will redefine 5 to 6, which the interpreter forbids ...
>
> One of those is actually syntactically valid.
>
> It just won’t do what you expect it to do.
>

Subject: Re: Two aces up Python's sleeve (Posting On Python-List Prohibited)
From: dn
Newsgroups: comp.lang.python
Organization: DWM
Date: Fri, 8 Nov 2024 19:09 UTC
References: 1 2 3 4 5 6
Path: eternal-september.org!news.eternal-september.org!feeder2.eternal-september.org!fu-berlin.de!uni-berlin.de!not-for-mail
From: PythonList@DancesWithMice.info (dn)
Newsgroups: comp.lang.python
Subject: Re: Two aces up Python's sleeve (Posting On Python-List Prohibited)
Date: Sat, 9 Nov 2024 08:09:49 +1300
Organization: DWM
Lines: 71
Message-ID: <mailman.88.1731092996.4695.python-list@python.org>
References: <seven-20241106014329@ram.dialup.fu-berlin.de>
<vgg5dn$ij48$1@solani.org>
<050c2ce9efd8442fb902ecc926afb1ee42fe6c34.camel@tilde.green>
<vgjoe9$2stii$2@dont-email.me> <vgjq77$aj8c$1@solani.org>
<59a78893-d96a-4f5b-921f-5ad862449ca2@DancesWithMice.info>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: news.uni-berlin.de pXyIfVUMRYsM1vPbYiwnYgKNR0TifK3tpNo/tc1v/yUQ==
Cancel-Lock: sha1:iNyr6IJ6MkXpZCRfJOOZA7Ih3PQ= sha256:817aUs8eluDNI1m96sK7qeDosS5yw4JpeoRcle9IEz0=
Return-Path: <PythonList@DancesWithMice.info>
X-Original-To: python-list@python.org
Delivered-To: python-list@mail.python.org
Authentication-Results: mail.python.org; dkim=pass
reason="2048-bit key; unprotected key"
header.d=danceswithmice.info header.i=@danceswithmice.info
header.b=A8DhJFWa; dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.001
X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'this:': 0.03; 'python:':
0.05; '=dn': 0.09; 'adapt': 0.09; 'browser,': 0.09; 'expression':
0.09; 'from:addr:danceswithmice.info': 0.09;
'from:addr:pythonlist': 0.09; 'pre': 0.09; 'python"': 0.09;
'question:': 0.09; 'shock': 0.09; 'subject:Python': 0.12;
'possible,': 0.15; 'alias': 0.16; 'applied:': 0.16; 'message-
id:@DancesWithMice.info': 0.16; 'received:51.254': 0.16;
'received:51.254.211': 0.16; 'received:51.254.211.219': 0.16;
'received:cloud': 0.16; 'received:rangi.cloud': 0.16; 'wrote:':
0.16; 'python': 0.16; 'probably': 0.17; 'to:addr:python-list':
0.20; 'languages': 0.22; 'code': 0.23; 'python,': 0.25; 'local':
0.27; '>>>': 0.28; 'header:User-Agent:1': 0.30; 'review,': 0.31;
'question': 0.32; 'driving': 0.32; 'python-list': 0.32;
'header:Organization:1': 0.32; 'but': 0.32; 'header:In-Reply-
To:1': 0.34; 'trying': 0.35; '"the': 0.35; 'fine': 0.35;
'submitted': 0.35; '...': 0.37; 'could': 0.37; 'received:192.168':
0.37; 'way': 0.38; 'use': 0.39; 'define': 0.40; 'learn': 0.40;
'something': 0.40; 'should': 0.40; 'above': 0.62; 'to:': 0.62;
'your': 0.64; 'received:51': 0.64; 'well': 0.65; 'rules': 0.70;
'subject:List': 0.71; 'left': 0.83; '1);': 0.84;
'subject:Posting': 0.84; 'zen': 0.84; 'badly': 0.91
DKIM-Filter: OpenDKIM Filter v2.11.0 vps.rangi.cloud 282C54415
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=danceswithmice.info;
s=staff; t=1731092993;
bh=vlCCdtRDjUSNFboG7tOfNoVCNXSTsG6ZohVlsNUSlXA=;
h=Date:From:Subject:To:References:In-Reply-To:From;
b=A8DhJFWaRM8KSIMKE2gaj+5YgjfgJJl97JfFA5jmkAlFibxvIMdF6X/jlIlwYuOJc
8q7NGFhg5BEoUYTupDXOXgc0ae0wRbO6EB1RSsA4LFjX8T9eooNmWzUiaq5xZY5pjy
NdN59DytwWJGQ/h6ccHkWvvUksAeZzANmSxr4/+6peFCyrs3h6TuhoQLnW73HI2C9M
sSHUUVr2gEyfel5vOMu672qLYXYIrmup3cbQ3/yyq9kJeK5BZJWJZQsQI1po7+MDOs
acn1U06bzbOnLJB0ZEfwMNnbYQDL1a0zkLPvQM+puOYsutzVXIqbLYdniClxlg8zZH
p1QN7bc1eZsrQ==
User-Agent: Mozilla Thunderbird
Content-Language: en-US
In-Reply-To: <vgjq77$aj8c$1@solani.org>
X-BeenThere: python-list@python.org
X-Mailman-Version: 2.1.39
Precedence: list
List-Id: General discussion list for the Python programming language
<python-list.python.org>
List-Unsubscribe: <https://mail.python.org/mailman/options/python-list>,
<mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive: <https://mail.python.org/pipermail/python-list/>
List-Post: <mailto:python-list@python.org>
List-Help: <mailto:python-list-request@python.org?subject=help>
List-Subscribe: <https://mail.python.org/mailman/listinfo/python-list>,
<mailto:python-list-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID: <59a78893-d96a-4f5b-921f-5ad862449ca2@DancesWithMice.info>
X-Mailman-Original-References: <seven-20241106014329@ram.dialup.fu-berlin.de>
<vgg5dn$ij48$1@solani.org>
<050c2ce9efd8442fb902ecc926afb1ee42fe6c34.camel@tilde.green>
<vgjoe9$2stii$2@dont-email.me> <vgjq77$aj8c$1@solani.org>
View all headers

On 8/11/24 14:40, Mild Shock via Python-list wrote:
> Well you can use your Browser, since
> JavaScript understand post and pre increment:

Question: are we talking Python or JavaScript?

> So we have x ++ equals in Python:

Trying to find a word-for-word translation serves as badly in
computer-programming languages as it does in human spoken-languages.
Learn how to adapt and embrace the differences...

>     x + = 1
>     x - 1

The above probably only 'works' (the way you expect) in the REPL.

> But I don't know how to combine an
> assignment and an expression into one
> expession. In JavaScript one can use

Again!

"Everything should be made as simple as possible, but no simpler."

Check out "The Zen of Python" and PEP-0008 for Python idioms.

> the comma:
>
> > x = 5
> 5
> > y = (x += 1, x - 1)
> 5
> > x = 5
> 5
> > y = (x += 1, x)
> 6
>
> But in Python the comma would create a tuple.

Exactly, just as driving on the left side of the road will be fine in
some countries but cause a crash in others. Learn the local rules FIRST!

The 'walrus operator' could be applied:

>>> x = 5
>>> y = (x := x + 1); x
6 >>> x, y
(6, 6)

However, if such were submitted for Code Review, unhappiness would result.

Was the question re-phrased to: how to ... in Python, we'd end-up with
something more like this:

>>> x = 5 # define
>>> x += 1 # increment
>>> y = x # alias
>>> x, y
(6, 6)

--
Regards,
=dn

Subject: Re: Two aces up Python's sleeve (Posting On Python-List Prohibited)
From: Mild Shock
Newsgroups: comp.lang.python
Date: Fri, 8 Nov 2024 19:49 UTC
References: 1 2 3 4 5 6 7
Path: eternal-september.org!news.eternal-september.org!feeder2.eternal-september.org!weretis.net!feeder8.news.weretis.net!reader5.news.weretis.net!news.solani.org!.POSTED!not-for-mail
From: janburse@fastmail.fm (Mild Shock)
Newsgroups: comp.lang.python
Subject: Re: Two aces up Python's sleeve (Posting On Python-List Prohibited)
Date: Fri, 8 Nov 2024 20:49:55 +0100
Message-ID: <vglq12$bqo4$1@solani.org>
References: <seven-20241106014329@ram.dialup.fu-berlin.de>
<vgg5dn$ij48$1@solani.org>
<050c2ce9efd8442fb902ecc926afb1ee42fe6c34.camel@tilde.green>
<vgjoe9$2stii$2@dont-email.me> <vgjq77$aj8c$1@solani.org>
<59a78893-d96a-4f5b-921f-5ad862449ca2@DancesWithMice.info>
<mailman.88.1731092996.4695.python-list@python.org>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Fri, 8 Nov 2024 19:49:54 -0000 (UTC)
Injection-Info: solani.org;
logging-data="387844"; mail-complaints-to="abuse@news.solani.org"
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Firefox/91.0 SeaMonkey/2.53.19
Cancel-Lock: sha1:zZuRXeCnXC8tvWdCYJNzEc/zqT0=
In-Reply-To: <mailman.88.1731092996.4695.python-list@python.org>
X-User-ID: eJwFwQkBwDAIA0BLlCeAnMIa/xJ2F4aDTUfAg0GsJEvn+M1SWp1eGdgljKF8b1NHnOhte3pHUoRffyvl3B9OahXE
View all headers

Ok here you go, the "walrus operator" is
actually a good lead, we have that this
here from JavaScript:

x++

respectively

++x

Can be replaced by the Python expression:

(x := x + 1) - 1

respectively

(x := x + 1)

Here is a test only testing x++:

Python 3.14.0a1 (tags/v3.14.0a1:8cdaca8, Oct 15 2024, 20:08:21)
>>> x = 5
>>> (x := x + 1) - 1
5 >>> x
6

dn schrieb:
.... irrational drivel removed ..> The 'walrus operator' could be applied:
>
> >>> x = 5
> >>> y = (x := x + 1); x
> 6
> >>> x, y
> (6, 6)... irrational drivel removed ..

Subject: Re: Two aces up Python's sleeve (Posting On Python-List Prohibited)
From: Thomas Passin
Newsgroups: comp.lang.python
Date: Fri, 8 Nov 2024 22:00 UTC
References: 1 2 3 4 5 6 7
Path: eternal-september.org!news.eternal-september.org!feeder2.eternal-september.org!fu-berlin.de!uni-berlin.de!not-for-mail
From: list1@tompassin.net (Thomas Passin)
Newsgroups: comp.lang.python
Subject: Re: Two aces up Python's sleeve (Posting On Python-List Prohibited)
Date: Fri, 8 Nov 2024 17:00:31 -0500
Lines: 76
Message-ID: <mailman.89.1731115813.4695.python-list@python.org>
References: <seven-20241106014329@ram.dialup.fu-berlin.de>
<vgg5dn$ij48$1@solani.org>
<050c2ce9efd8442fb902ecc926afb1ee42fe6c34.camel@tilde.green>
<vgjoe9$2stii$2@dont-email.me> <vgjq77$aj8c$1@solani.org>
<59a78893-d96a-4f5b-921f-5ad862449ca2@DancesWithMice.info>
<5b6c9d39-2a1a-4554-8cd8-da123411eb81@tompassin.net>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: news.uni-berlin.de Rh8fsO/rGztXTR3AYkXq7Q2PyqU3NAS+4NInG7QzxMQQ==
Cancel-Lock: sha1:hm8s8FksLn5fun0niLMdMXKsQxg= sha256:Huju9Y34CCt2qHpNxyyPn/vX50siqb0BAc94DXMALjA=
Return-Path: <list1@tompassin.net>
X-Original-To: python-list@python.org
Delivered-To: python-list@mail.python.org
Authentication-Results: mail.python.org; dkim=pass
reason="2048-bit key; unprotected key"
header.d=tompassin.net header.i=@tompassin.net header.b=En7T/88Q;
dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.004
X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'this:': 0.03; 'python:':
0.05; 'adapt': 0.09; 'browser,': 0.09; 'expression': 0.09; 'pre':
0.09; 'python"': 0.09; 'question:': 0.09; 'shock': 0.09;
'subject:Python': 0.12; 'possible,': 0.15; 'alias': 0.16;
'applied:': 0.16; 'pythonic': 0.16; 'received:10.0.0': 0.16;
'received:100.112': 0.16; 'received:64.90': 0.16;
'received:64.90.62': 0.16; 'received:64.90.62.162': 0.16;
'received:dreamhost.com': 0.16; 'wrote:': 0.16; 'python': 0.16;
'probably': 0.17; 'pm,': 0.19; 'to:addr:python-list': 0.20;
'languages': 0.22; 'code': 0.23; 'python,': 0.25; 'programming':
0.25; 'local': 0.27; '>>>': 0.28; 'header:User-Agent:1': 0.30;
'review,': 0.31; 'question': 0.32; 'driving': 0.32; 'python-list':
0.32; 'received:10.0': 0.32; 'received:mailchannels.net': 0.32;
'received:relay.mailchannels.net': 0.32; 'but': 0.32; 'header:In-
Reply-To:1': 0.34; 'trying': 0.35; '"the': 0.35; 'fine': 0.35;
'submitted': 0.35; '...': 0.37; 'could': 0.37; 'way': 0.38; 'use':
0.39; 'received:100': 0.39; 'still': 0.40; 'define': 0.40;
'learn': 0.40; 'something': 0.40; 'should': 0.40; 'above': 0.62;
'to:': 0.62; 'your': 0.64; 'well': 0.65; 'header:Received:6':
0.67; 'received:64': 0.68; 'rules': 0.70; 'subject:List': 0.71;
'left': 0.83; '1);': 0.84; 'subject:Posting': 0.84; 'zen': 0.84;
'\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0': 0.84; 'badly': 0.91
X-Sender-Id: dreamhost|x-authsender|tpassin@tompassin.net
ARC-Seal: i=1; s=arc-2022; d=mailchannels.net; t=1731103233; a=rsa-sha256;
cv=none;
b=336jk93q4RJCkUDMWg41QCC/gcLRzT42CPywz0JtQgnpmyI1fIv+alELOLYSpsxXCVjuGH
Q8DEvAKr+zoILyjx2S8YaNAIdeJAaYg5GOPD8SLlXDAHx7zPRNEN/tWo1Tt/rElFWJI3c5
QJhJ8yUhnVpGoaug/c0ERI8fJyqdhdzuXbBiSYAhVdSDDC2ZMCaKHxLUkBThbiZFZLgYNR
ycLhrrE5HDStkXyrRK+m4VArbFAyT3kQY4IrapHYvOOS2Npr4IIzm65f0WjQO0Zk2bq57z
7IIAaKUX8+bIAIL9sU2FTFhqWTe2uHpqlgv80PJcDf00nepGryWJKJ0ti1ZHTw==
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed;
d=mailchannels.net; s=arc-2022; t=1731103233;
h=from:from:reply-to:subject:subject:date:date:message-id:message-id:
to:to:cc:mime-version:mime-version:content-type:content-type:
content-transfer-encoding:content-transfer-encoding:
in-reply-to:in-reply-to:references:references:dkim-signature;
bh=S8IcJ9ieTc0CHpnIz6rSM5/dqUXnbVlj4pEVUNYDia4=;
b=NqZLdVagUuR0LOok/KZwjRbhihNyGCdgYeJuk7PWURtSPSCc0XEviaxcZw8y/w8qJ2nJfV
AZIw6dVOf6PElAhqRlEW0q9cnn6B25YFl/t3ORNJ82qD8zxraVtBPhdnaxCi8QR00RtDgA
MK1tib54xKMsjDq6Fnei2bcFOlAqHaE1DpOUVZywNd9ZZAEFuZs3emRAutlP3FvQ6FtwHf
86F9Mg0HLflTuSVc8plt4QX3JBkN9jXBYHa5i+3TV1D9lS4omyPg/Z1ktUG6v3obF6rNg6
fjUE06CoBMoNSKNzMdLdrgTBZ5SC6plqjUEuE+0zgKWJtNuVtJXqVBthsSNeQg==
ARC-Authentication-Results: i=1; rspamd-56654dd69b-v7p4n;
auth=pass smtp.auth=dreamhost smtp.mailfrom=list1@tompassin.net
X-Sender-Id: dreamhost|x-authsender|tpassin@tompassin.net
X-MC-Relay: Neutral
X-MailChannels-SenderId: dreamhost|x-authsender|tpassin@tompassin.net
X-MailChannels-Auth-Id: dreamhost
X-Shade-Thread: 4ef115826633fc1f_1731103233434_576023272
X-MC-Loop-Signature: 1731103233434:202020567
X-MC-Ingress-Time: 1731103233434
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tompassin.net;
s=dreamhost; t=1731103233;
bh=S8IcJ9ieTc0CHpnIz6rSM5/dqUXnbVlj4pEVUNYDia4=;
h=Date:Subject:To:From:Content-Type:Content-Transfer-Encoding;
b=En7T/88QpNxFOyjJfd4EvGSrQ+DL/8P2n72a8OxVve978hRB/90QLyIHYrqlNWcfj
6rGlJy64oe1JR1CL54d3WcembCjJc31EaeUrNxV06x8ERoIYKhm+kWUbwu8LSWq1Jx
H5tkfdwh6s9BWzkEtRbFMbacqAiOM5HCt2e4IlocLfc4q4CMnZqtAcCt1My2TY8I5/
brBT/KO1Imlv2jgmT2J8hAE6ZUtMroGsy7HeQ8uZG2lznhGnP3aDwyFh1yYMSF49tw
sv9+9GoSluAmmlnZ9FawEg1Mt2Yxy6Qz/uQUj2QMOlMMyw4NWTvM5/AAFuqDZ3a+VS
4vOxEqFx5h3Sg==
User-Agent: Mozilla Thunderbird
Content-Language: en-US
In-Reply-To: <59a78893-d96a-4f5b-921f-5ad862449ca2@DancesWithMice.info>
X-BeenThere: python-list@python.org
X-Mailman-Version: 2.1.39
Precedence: list
List-Id: General discussion list for the Python programming language
<python-list.python.org>
List-Unsubscribe: <https://mail.python.org/mailman/options/python-list>,
<mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive: <https://mail.python.org/pipermail/python-list/>
List-Post: <mailto:python-list@python.org>
List-Help: <mailto:python-list-request@python.org?subject=help>
List-Subscribe: <https://mail.python.org/mailman/listinfo/python-list>,
<mailto:python-list-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID: <5b6c9d39-2a1a-4554-8cd8-da123411eb81@tompassin.net>
X-Mailman-Original-References: <seven-20241106014329@ram.dialup.fu-berlin.de>
<vgg5dn$ij48$1@solani.org>
<050c2ce9efd8442fb902ecc926afb1ee42fe6c34.camel@tilde.green>
<vgjoe9$2stii$2@dont-email.me> <vgjq77$aj8c$1@solani.org>
<59a78893-d96a-4f5b-921f-5ad862449ca2@DancesWithMice.info>
View all headers

On 11/8/2024 2:09 PM, dn via Python-list wrote:
> On 8/11/24 14:40, Mild Shock via Python-list wrote:
>> Well you can use your Browser, since
>> JavaScript understand post and pre increment:
>
> Question: are we talking Python or JavaScript?
>
>
>> So we have x ++ equals in Python:
>
> Trying to find a word-for-word translation serves as badly in computer-
> programming languages as it does in human spoken-languages. Learn how to
> adapt and embrace the differences...
>
>
>>      x + = 1
>>      x - 1
>
> The above probably only 'works' (the way you expect) in the REPL.
>
>
>> But I don't know how to combine an
>> assignment and an expression into one
>> expession. In JavaScript one can use
>
> Again!
>
> "Everything should be made as simple as possible, but no simpler."
>
> Check out "The Zen of Python" and PEP-0008 for Python idioms.
>
>
>> the comma:
>>
>>  > x = 5
>> 5
>>  > y = (x += 1, x - 1)
>> 5
>>  > x = 5
>> 5
>>  > y = (x += 1, x)
>> 6
>>
>> But in Python the comma would create a tuple.
>
> Exactly, just as driving on the left side of the road will be fine in
> some countries but cause a crash in others. Learn the local rules FIRST!
>
>
> The 'walrus operator' could be applied:
>
> >>> x = 5
> >>> y = (x := x + 1); x
> 6
> >>> x, y
> (6, 6)
>
> However, if such were submitted for Code Review, unhappiness would result.
>
>
> Was the question re-phrased to: how to ... in Python, we'd end-up with
> something more like this:
>
> >>> x = 5  # define
> >>> x += 1  # increment
> >>> y = x  # alias
> >>> x, y
> (6, 6)

Or, still Pythonic but simpler:

>>> x = 5
>>> y = x = x + 1
>>> x, y
(6, 6)

1

rocksolid light 0.9.8
clearnet tor