Rocksolid Light

News from da outaworlds

mail  files  register  groups  login

Message-ID:  

You will triumph over your enemy.


comp / comp.lang.python / Re: Two python issues (Posting On Python-List Prohibited)

SubjectAuthor
* Two python issuesRaymond Boute
+* Re: Two python issuesPiergiorgio Sartor
|`- Re: Two python issues (Posting On Python-List Prohibited)Lawrence D'Oliveiro
`- Re: Two python issuesStefan Ram

1
Subject: Two python issues
From: Raymond Boute
Newsgroups: comp.lang.python
Date: Tue, 5 Nov 2024 14:48 UTC
References: 1
Path: eternal-september.org!news.eternal-september.org!feeder2.eternal-september.org!fu-berlin.de!uni-berlin.de!not-for-mail
From: raymond.boute@pandora.be (Raymond Boute)
Newsgroups: comp.lang.python
Subject: Two python issues
Date: Tue, 5 Nov 2024 15:48:07 +0100
Lines: 36
Message-ID: <mailman.80.1730839406.4695.python-list@python.org>
References: <700403c2-e052-4670-b2ec-eaf9b4babada@pandora.be>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: news.uni-berlin.de QW5XEfkMaOHXERL6fahY1Q3waWYuoXjVCXSkWbz5Ef6Q==
Cancel-Lock: sha1:SpcBqJBlFlkuFpkfdC+Drf+9nsc= sha256:Rp0ZYm4T3sQpyON3Sf5SppUT3D7qq6h0AW7zUxm56tA=
Return-Path: <raymond.boute@pandora.be>
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=pandora.be header.i=@pandora.be header.b=NLZi8dFx;
dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: UNSURE 0.220
X-Spam-Level: **
X-Spam-Evidence: '*H*': 0.59; '*S*': 0.03; 'comments': 0.03;
'example:': 0.09; 'subject:python': 0.10; '(b)': 0.16; 'option.':
0.16; 'received:be': 0.16; 'welcome.': 0.16; 'python': 0.16;
'subject:issues': 0.19; 'to:addr:python-list': 0.20; 'idea': 0.24;
'anything': 0.25; '>>>': 0.28; 'error': 0.29; 'header:User-
Agent:1': 0.30; 'seem': 0.31; 'elements': 0.32; 'language.': 0.32;
'negative': 0.32; 'returning': 0.32; 'but': 0.32; 'same': 0.34;
'item': 0.35; 'lists': 0.37; 'currently': 0.37; 'using': 0.37;
'list': 0.39; 'changes': 0.39; 'otherwise': 0.39; 'should': 0.40;
'best': 0.61; 'bad': 0.67; 'items': 0.68; 'refers': 0.69;
'essential': 0.70; 'longer': 0.71; 'covered': 0.75; 'solutions.':
0.75; '(e.g.,': 0.76; 'poor': 0.76; 'cleaner': 0.84; 'indices':
0.84; 'preceding': 0.84; 'strings': 0.84; 'affect': 0.91;
'suffer': 0.91
User-Agent: Mozilla Thunderbird
Content-Language: en-US
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pandora.be; s=p24;
t=1730818089; bh=5x8kcXClyn0w692908zIMOGWlV5ioo7CZFLarF1Ow5o=;
h=Message-ID:Date:MIME-Version:To:From:Subject:Content-Type:
Content-Transfer-Encoding:From;
b=NLZi8dFx1hxI1K7N8MVv7VobsAqywU1mBsDBt+4ks04RXSbgpqNtWetdmg2dcP7/Z
fWYjna3PqkEwgg1jgPR6RryzzqOf6KijVEq6zh+Eel8/cgieKHmyzwuBU8Pxha4ZVk
hqNY+23d4vz0iurLI1DFRfxAeMk1QdIHBuLL5lTVLGmWLoOPFbsAd3YswXQgYVJY57
EERjQMIsqLBee+sU53tNeskDl7pqxFqbKq8A1w3udvw4NkUPpSuRBOWuSt/B3Bz4Sa
NBg5qvTdTAu1pXBcO1/bHCM3ww5oC17trrFfWhLoLyjrBw4wqovKZKkNwl7LghaBys
EAgJTk7Rs95ZQ==
X-Mailman-Approved-At: Tue, 05 Nov 2024 15:43:25 -0500
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: <700403c2-e052-4670-b2ec-eaf9b4babada@pandora.be>
View all headers

L.S.,

Python seem to suffer from a few poor design decisions regarding strings
and lists that affect the elegance of the language.

(a) An error-prone "feature" is returning -1 if a substring is not found
by "find", since -1 currently refers to the last item. An example:

>>> s = 'qwertyuiop'
>>> s[s.find('r')]
'r'
>>> s[s.find('p')]
'p'
>>> s[s.find('a')]
'p'
>>>

If "find" is unsuccessful, an error message is the only clean option.
Moreover, using index -1 for the last item is a bad choice: it should be
len(s) - 1 (no laziness!).
Negative indices should be reserved for elements preceding the element
with index 0 (currently not implemented, but a must for orthogonal
design supporting general sequences).

(b) When using assignment for slices, only lists with the same length as
the slice should be acceptable, otherwise an error should be given. 
Anything that re-indexes items not covered by the slice is against the
essential idea of assignment. For changes that imply re-indexing (e.g.,
inserting a list longer than the slice), Python offers cleaner solutions.

Comments are welcome.

With best regards,

Raymond

Subject: Re: Two python issues
From: Piergiorgio Sartor
Newsgroups: comp.lang.python
Organization: A noiseless patient Spider
Date: Tue, 5 Nov 2024 21:27 UTC
References: 1 2
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: piergiorgio.sartor.this.should.not.be.used@nexgo.REMOVETHIS.de (Piergiorgio Sartor)
<piergiorgio.sartor.this.should.not.be.used@nexgo.REMOVETHIS.de>
Newsgroups: comp.lang.python
Subject: Re: Two python issues
Date: Tue, 5 Nov 2024 22:27:53 +0100
Organization: A noiseless patient Spider
Lines: 61
Message-ID: <p7fqvk-jt4.ln1@lazy.lzy>
References: <700403c2-e052-4670-b2ec-eaf9b4babada@pandora.be>
<mailman.80.1730839406.4695.python-list@python.org>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Tue, 05 Nov 2024 22:28:42 +0100 (CET)
Injection-Info: dont-email.me; posting-host="2a0534154ec88a34d27315aba77c9ccb";
logging-data="1812733"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/0QlSuaTuOtofzX8yKA580"
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:0LVOYi4X9FqckxeyNHL/h61+rLU=
Content-Language: it, en-GB
In-Reply-To: <mailman.80.1730839406.4695.python-list@python.org>
View all headers

On 05/11/2024 15.48, Raymond Boute wrote:
> L.S.,
>
> Python seem to suffer from a few poor design decisions regarding strings
> and lists that affect the elegance of the language.
>
> (a) An error-prone "feature" is returning -1 if a substring is not found
> by "find", since -1 currently refers to the last item. An example:
>
> >>> s = 'qwertyuiop'
> >>> s[s.find('r')]
> 'r'
> >>> s[s.find('p')]
> 'p'
> >>> s[s.find('a')]
> 'p'
> >>>
>
> If "find" is unsuccessful, an error message is the only clean option.
> Moreover, using index -1 for the last item is a bad choice: it should be
> len(s) - 1 (no laziness!).
> Negative indices should be reserved for elements preceding the element
> with index 0 (currently not implemented, but a must for orthogonal
> design supporting general sequences).
>
> (b) When using assignment for slices, only lists with the same length as
> the slice should be acceptable, otherwise an error should be given.
> Anything that re-indexes items not covered by the slice is against the
> essential idea of assignment. For changes that imply re-indexing (e.g.,
> inserting a list longer than the slice), Python offers cleaner solutions.
>
> Comments are welcome.

To write the nested expression, s[s.find(...)] it
means you're 200% sure of what happens in case of
not found.
It could be -1 or None or [] or anything.

So, the really correct thing to do, since you know
what will happen in case of not found, is *not* to
write the nested form, but explicitly state what it
will happen.

r = s.find(...)
if r is good:
s[r]
else:
print('not found')

Which is much easier to read, to debug, etc.

To paraphrase someone: "If the length of a
program would be measured by the time needed
to understand it, some programs are too short
to be short."

bye,

--

piergiorgio

Subject: Re: Two python issues (Posting On Python-List Prohibited)
From: Lawrence D'Oliv
Newsgroups: comp.lang.python
Organization: A noiseless patient Spider
Date: Tue, 5 Nov 2024 21:56 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 python issues (Posting On Python-List Prohibited)
Date: Tue, 5 Nov 2024 21:56:01 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 8
Message-ID: <vge49g$1nfmk$4@dont-email.me>
References: <700403c2-e052-4670-b2ec-eaf9b4babada@pandora.be>
<mailman.80.1730839406.4695.python-list@python.org>
<p7fqvk-jt4.ln1@lazy.lzy>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Tue, 05 Nov 2024 22:56:01 +0100 (CET)
Injection-Info: dont-email.me; posting-host="4f0f004de3a819e2f35c6d7b57515410";
logging-data="1818324"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/biVjNnHFb/0HUQnC31q/J"
User-Agent: Pan/0.160 (Toresk; )
Cancel-Lock: sha1:JCYRSk6MnYxzGV519IJX3KIGBac=
View all headers

On Tue, 5 Nov 2024 22:27:53 +0100, Piergiorgio Sartor wrote:

> To write the nested expression, s[s.find(...)] it means you're 200% sure
> of what happens in case of not found.

Or use s.index(...) instead of s.find(...). Then you get an exception if
the substring is not found, instead of having your program produce some
mysteriously-incorrect result.

Subject: Re: Two python issues
From: Stefan Ram
Newsgroups: comp.lang.python
Organization: Stefan Ram
Date: Wed, 6 Nov 2024 00:26 UTC
References: 1
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 python issues
Date: 6 Nov 2024 00:26:51 GMT
Organization: Stefan Ram
Lines: 44
Expires: 1 Jul 2025 11:59:58 GMT
Message-ID: <two-20241106011638@ram.dialup.fu-berlin.de>
References: <mailman.80.1730839406.4695.python-list@python.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-Trace: news.uni-berlin.de eAeZufwL/YXK4c0fXfn6kgN2XlWGJcToqz/pr3D5WrD/oe
Cancel-Lock: sha1:4bSHaAjnI+OGN2jqBcAlajyo+VA= sha256:NXUAvUSdfpA0hN82Xt+GMiSdP0fKJlediFgbk8Wz11w=
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

Raymond Boute <raymond.boute@pandora.be> wrote or quoted:
> >>> s[s.find('a')]
>'p'

If you want exceptions, index() is your jam.

>Moreover, using index -1 for the last item is a bad choice: it should be
>len(s) - 1 (no laziness!).

This feature is the bee's knees, man.

last_item = my_list[ -1 ]
second_to_last = my_list[ -2 ]

Way cleaner than my_list[ len( my_list )- 1 ], don't you think?

>(b) When using assignment for slices, only lists with the same length as
>the slice should be acceptable, otherwise an error should be given. 

The current setup lets you pull off some seriously gnarly code
maneuvers:

python
# Insert elements
my_list[ 2: 2 ]=[ 4, 5, 6 ]

# Replace a section
my_list[ 1: 4 ]=[ 10, 11 ]

# Delete elements
my_list[ 2: 5 ]= []

These moves are slick and expressive. Forcing exact length
matching would only cramp our style.

Look, I get it. You're probably fresh out of coding bootcamp,
thinking you can reinvent the wheel. But trust me, these features
are solid gold. They're not perfect, sure, but they're about
as good as finding a parking spot in San Francisco on a Saturday
night. So before you go throwing shade at Python, maybe spend
some more time with it. You might just find it grows on you like
a NorCal redwood. Keep coding, and don't let the fog get you down!

1

rocksolid light 0.9.8
clearnet tor