Steven D'Aprano <[email protected]> added the comment:
David, I'm pretty sure that SilentGhost is correct. You are misreading the
error message: it has nothing to do with the negative index.
The problem is that your `insert_value` function returns None, not the list. I
believe that what you have done is tested the function once, with a positive
index and then tried it again with a negative index:
# this works fine, the first time
str_list4 = list_function.insert_value(str_list4, 's', 1)
# but fails the second time
str_list4 = list_function.insert_value(str_list4, 's', -1)
The reason is that functions returns None by default, so you have replaced
str_list4 with None. Then on the second call to the function, this line fails:
for index in my_list:
because my_list is None. When Python gives you an error message, PLEASE READ IT
because the interpreter does not lie, it knows what caused the failure:
TypeError: 'NoneType' object is not iterable
Python is used by hundreds of thousands of people and they probably would have
noticed a severe, fundamental flaw like the inability to pass negative numbers
to other modules by now. As a beginner, 99.99% of the "bugs" you find will be
in your own code, not the language.
(It has been said that the difference between a beginner and an expert is that
the beginner assumes every bug is the language's fault, and an expert knows
that nearly every bug is his own fault.)
As SilentGhost says, this list is not a help-desk. Please don't follow up with
extra questions here, I won't answer. If you want help or advice, please
subscribe to the tutor mailing list
https://mail.python.org/mailman/listinfo/tutor
where there will be plenty of people happy to help.
If you still believe that your code is correct, and you've found a bug that has
escaped thousands of full-time Python programmers (it does happen...) then
please take the time to read this:
http://www.sscce.org/
and follow the advice given there. It's written for Java, not Python ,but the
advice applies to any language.
Thank you.
----------
nosy: +steven.daprano
_______________________________________
Python tracker <[email protected]>
<https://bugs.python.org/issue36872>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com