[issue46302] IndexError inside list comprehension + workaround

2022-01-08 Thread Pierre Fortin


Pierre Fortin  added the comment:

[Thanks for the replies! I was trying to post this before seeing them.]

Major egg on face...
The more complex the code becomes, the more likely you will be burned by a 
rookie mistake...
var = ''
var[0]  WILL give IndexError  -- Duh!
It was buried in the each.split('=') returning an empty string -- that's what 
you get for making things easier for the user. 
The easier code is to use, the more complex it must be...

Sorry for the noise.

--

___
Python tracker 
<https://bugs.python.org/issue46302>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue46302] IndexError inside list comprehension + workaround

2022-01-07 Thread Pierre Fortin


New submission from Pierre Fortin :

var = "u2"
var.strip()[0] 
Works as expected, except that it returns IndexError (instead of "u") if used 
in a list comprehension -- at least, that's where I found it.  Attached example 
script illustrates the issue.
Call it with "mytest N" where N is 1 (fails), 2 (works), 3 (fails).
mytest 1 -- KeyError expected; this was due to infile design change
adding a digit to previously single char code
mytest 2 -- workaround to actual issue in next test
mytest 3 -- adding [0] fails when used in list comprehension

--
components: Interpreter Core
files: mytest
messages: 410054
nosy: NetAlien
priority: normal
severity: normal
status: open
title: IndexError inside list comprehension + workaround
type: behavior
versions: Python 3.8
Added file: https://bugs.python.org/file50548/mytest

___
Python tracker 
<https://bugs.python.org/issue46302>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com