Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #196981
| From | Mild Shock <janburse@fastmail.fm> |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | Re: Two aces up Python's sleeve |
| Date | 2024-11-08 01:47 +0100 |
| Message-ID | <vgjn2h$kiom$1@solani.org> (permalink) |
| References | (2 earlier) <050c2ce9efd8442fb902ecc926afb1ee42fe6c34.camel@tilde.green> <vgihe5$9tsc$1@solani.org> <lp4sgdFg90oU1@mid.individual.net> <vgjlqg$ki9n$1@solani.org> <vgjm1s$ki9n$2@solani.org> |
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. >>> >> >
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar
Re: Two aces up Python's sleeve Mild Shock <janburse@fastmail.fm> - 2024-11-06 17:27 +0100
Re: Two aces up Python's sleeve Annada Behera <annada@tilde.green> - 2024-11-07 12:55 +0530
Re: Two aces up Python's sleeve Mild Shock <janburse@fastmail.fm> - 2024-11-07 15:04 +0100
Re: Two aces up Python's sleeve Greg Ewing <greg.ewing@canterbury.ac.nz> - 2024-11-08 11:15 +1300
Re: Two aces up Python's sleeve dn <PythonList@DancesWithMice.info> - 2024-11-08 13:07 +1300
Re: Two aces up Python's sleeve Mild Shock <janburse@fastmail.fm> - 2024-11-08 01:25 +0100
Re: Two aces up Python's sleeve Mild Shock <janburse@fastmail.fm> - 2024-11-08 01:29 +0100
Re: Two aces up Python's sleeve Mild Shock <janburse@fastmail.fm> - 2024-11-08 01:47 +0100
Re: Two aces up Python's sleeve (Posting On Python-List Prohibited) Lawrence D'Oliveiro <ldo@nz.invalid> - 2024-11-08 01:10 +0000
Re: Two aces up Python's sleeve (Posting On Python-List Prohibited) Mild Shock <janburse@fastmail.fm> - 2024-11-08 02:40 +0100
Re: Two aces up Python's sleeve (Posting On Python-List Prohibited) dn <PythonList@DancesWithMice.info> - 2024-11-09 08:09 +1300
Re: Two aces up Python's sleeve (Posting On Python-List Prohibited) Mild Shock <janburse@fastmail.fm> - 2024-11-08 20:49 +0100
Re: Two aces up Python's sleeve (Posting On Python-List Prohibited) Thomas Passin <list1@tompassin.net> - 2024-11-08 17:00 -0500
csiph-web