Rocksolid Light

News from da outaworlds

mail  files  register  groups  login

Message-ID:  

BOFH excuse #33: piezo-electric interference


comp / comp.lang.python / Re: Flubbed it in the second interation through the string: range error... HOW?

SubjectAuthor
o Re: Flubbed it in the second interation through the string: range error... HOW?Thomas Passin

1
Subject: Re: Flubbed it in the second interation through the string: range error... HOW?
From: Thomas Passin
Newsgroups: comp.lang.python
Date: Wed, 29 May 2024 05:14 UTC
References: 1 2 3
Path: eternal-september.org!news.eternal-september.org!feeder3.eternal-september.org!fu-berlin.de!uni-berlin.de!not-for-mail
From: list1@tompassin.net (Thomas Passin)
Newsgroups: comp.lang.python
Subject: Re: Flubbed it in the second interation through the string: range
error... HOW?
Date: Wed, 29 May 2024 01:14:07 -0400
Lines: 42
Message-ID: <mailman.54.1716960627.2909.python-list@python.org>
References: <1901134155.5453771.1716957203090.ref@mail.yahoo.com>
<1901134155.5453771.1716957203090@mail.yahoo.com>
<28615cd5-5b77-44bb-ba3a-5ce6cad7c943@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 JnHWUGgnrXdL39xys8v81w5dt01AQdAyZxJ/8zTY3jpg==
Cancel-Lock: sha1:1gnpNXmkuiCtyIq8tTjjpIkkT7U= sha256:BnjZWYICyYfqAq8W7ipFSHQW7ITTKifrBeroiBxLD6A=
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=jAPtrHed;
dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.009
X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'def': 0.04; 'traceback':
0.04; '(most': 0.05; 'string': 0.07; 'elif': 0.09; 'readable':
0.09; 'string,': 0.09; '(because': 0.16; '2024': 0.16;
'lowercase': 0.16; 'received:10.0.0': 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; 'subject:second': 0.16;
'subject:string': 0.16; 'wrote:': 0.16; 'to:addr:python-list':
0.20; 'code': 0.23; 'lines': 0.23; 'run': 0.23; 'do,': 0.26;
'skip:{ 20': 0.26; 'error': 0.29; 'header:User-Agent:1': 0.30;
'am,': 0.31; "doesn't": 0.32; 'do.': 0.32; 'letter,': 0.32;
'python-list': 0.32; 'received:10.0': 0.32;
'received:mailchannels.net': 0.32;
'received:relay.mailchannels.net': 0.32; "i'm": 0.33; 'header:In-
Reply-To:1': 0.34; 'trying': 0.35; 'following': 0.35; 'also,':
0.36; 'cell': 0.36; 'using': 0.37; "it's": 0.37; '8bit%:14': 0.38;
'block': 0.39; 'much.': 0.39; 'explain': 0.40; 'something': 0.40;
'want': 0.40; 'sample': 0.61; 'lower': 0.62; 'skip:m 20': 0.63;
'pass': 0.64; 'your': 0.64; 'header:Received:6': 0.67;
'received:64': 0.67; 'that,': 0.67; 'subject:through': 0.69;
'kindly': 0.80; '"when': 0.84; 'subject: \n ': 0.84; 'you:': 0.84
X-Sender-Id: dreamhost|x-authsender|tpassin@tompassin.net
ARC-Seal: i=1; s=arc-2022; d=mailchannels.net; t=1716959650; a=rsa-sha256;
cv=none;
b=mK4mF+/5xoQEm/j34WpHNtqFdPvuMa6ZGtHm8OtUFUzKk04cfUq5KoYEGj4uvEDfkrLTYk
A8u6dKrBqeg7/Ax/CY9dQNY+2Wk66Ya/mJWeey11zON6FjBKkiAaoJueRrjqv8vdOFsPC9
R+rKLjpkp5JLkN/8Np4icOR7iHp8OFdzqebJP5hRUqLRs8CLzwuv5/Pgz4AefHOE/GDJ2e
giWLYNoPQvujKfN34tzETup2kKjN+CAUQ1Pvq4Ih9MbPEi0T9xLcj2vVWE0eNQPIzJ7Luh
sjIiACeXLKkxwbeeVDq35qbFRaq8FlJAAk88NXeDU6CKsAc2qCUK6B2N5HiLUg==
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed;
d=mailchannels.net; s=arc-2022; t=1716959650;
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=s/1jZR2OiL4hV2r4doG/uI6oLQloiEpXDlqoRFVXhyI=;
b=o4yt640FpMlJUXMlcmcmjsiFleCXHZLE7si+D1Qy/JfPA4yrduZNIsFA5Jubuvj8XQwY/t
8HSYEEdWD4/fCKtya9tuCmUNFzEMZO38us+d48iFNFfwqozslNKr6DchrJSD683mZrvXek
7AmwJu29FQRWmmXH8ktirfosdJc1FHyKvSIdoxlggPJHfSonc/hDWsPDta3xQh5TU93jW1
WeHHARsI9xiXXWNEcgOXbQS3P8TlXiwUG7NuQxv38ITvJSzLddEDZ3oOuNhMF1nrz/4b4/
nwe3akaSiV2zWJKVilxQqkDAkllQ9/A5vTaL95koyaEBYhtJ5GxcWp5N9ObZdA==
ARC-Authentication-Results: i=1; rspamd-5d55749bb4-xx59k;
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-Troubled-Power: 2a4812f50394603c_1716959650315_1937173348
X-MC-Loop-Signature: 1716959650315:3268572687
X-MC-Ingress-Time: 1716959650315
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tompassin.net;
s=dreamhost; t=1716959649;
bh=s/1jZR2OiL4hV2r4doG/uI6oLQloiEpXDlqoRFVXhyI=;
h=Date:Subject:To:From:Content-Type:Content-Transfer-Encoding;
b=jAPtrHedGa9wU/Zc88tdnXtppDoxLAjHaYqjrsZidcq6auJFpapxFx1QqdUU0ZE2M
3CZsR2DiiWrAcr9qhOei7P6Nsh+Ei/ryjZWJ4KtibGfT8K3d9OhH1VeimJ9oZ+nMYv
j1waXgI1PHJEOnUegu66h7ubOlkvWuZqWZZstjtXFJ2qXg3gr5DliC/RZJgtJeW5XF
TQo/rMS3zWDChahfiEYAQOofQL8wqtbMnUhNxCDwmVOOX03qG1yxLk8FhO/4Qwx+VI
4Gg5oMVkXGgrx0mDC4GvYNh1KApUUAAqbGgGSCEQd3MK0X4sqsFG6jTY39+NL4cCoT
rznxfQcDyE1Og==
User-Agent: Mozilla Thunderbird
Content-Language: en-US
In-Reply-To: <1901134155.5453771.1716957203090@mail.yahoo.com>
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: <28615cd5-5b77-44bb-ba3a-5ce6cad7c943@tompassin.net>
X-Mailman-Original-References: <1901134155.5453771.1716957203090.ref@mail.yahoo.com>
<1901134155.5453771.1716957203090@mail.yahoo.com>
View all headers

Your code is unreadable. The lines have all run together. And after
that, kindly explain what you want your code sample to do. "Process"
doesn't say much.

From what I can make out about what you are trying to do, you would do
better to index through your string with

for i, chr in enumerate(name):
# do something with the character

Also, it's 2024 ... time to start using f-strings (because they are more
readable than str.format())

On 5/29/2024 12:33 AM, Kevin M. Wilson via Python-list wrote:
> The following is my effort to understand how to process a string, letter, by letter:
> def myfunc(name):        index = 0    howmax = len(name)    # while (index <= howmax):    while (index < howmax):        if (index % 2 == 0):            print('letter to upper = {}, index {}!'.format(name[index], index))            name = name[index].upper()            print('if block {} and index {}'.format(name[index], index))        elif (index % 2 > 0):            print(index)            print('Start: elseif block, index is {}, letter is {}'.format(index, name))            # print('letter to lower = {}'.format(name[index]))            # print('Already lowercase do noting: name = {}'.format(name[index]))        index += 1        # index = name.upper()
>     return name
> myfunc('capitalism')
> Error message:                        Not making sense, index is 1, letter s/b 'a'letter to upper = c, index 0!
> if block C and index 0
> 1
> Start: elseif block, index is 1, letter is C
> ---------------------------------------------------------------------------
> IndexError Traceback (most recent call last)
> Cell In[27], line 21
> 17 # index = name.upper()
> 19 return name
> ---> 21 myfunc('capitalism')
>
> Cell In[27], line 8, in myfunc(name)
> 6 while (index < howmax):
> 7 if (index % 2 == 0):
> ----> 8 print('letter to upper = {}, index {}!'.format(name[index], index))
> 9 name = name[index].upper()
> 10 print('if block {} and index {}'.format(name[index], index))
>
> IndexError: string index out of range***************************************************
> So, I'm doing something... Stupid!!
> ***************************************************
> "When you pass through the waters, I will be with you: and when you pass through the rivers, they will not sweep over you. When you walk through the fire, you will not be burned: the flames will not set you ablaze."
> Isaiah 43:2

1

rocksolid light 0.9.8
clearnet tor