Ask coding questions

← Back to all posts
list[index] returned None instead of String
rediar (402)

This bug has been driving me crazy, couldn't figure out it at all. You can see the error when running the code. Can someone help please???
(sorry if not too detailed, am tired)
Clarification: once in a while a random element in the list turns into None

Codejira (166)

Your program crashes when rstuff, taken from the list contents, is None, because it is impossible to check whether there's a \n in None (line 8).
I inserted following code at line 58:

    if rstuff == None:
        print("halted before error")
        print("Contents:", contents)
        print("Index:", index)

and indeed found in contents: 'I', 'am', None, 'good', 'at', 'typing."',
The None replaced the element "so" but I'm afraid I have no clue how that happened.
Perhaps this gives you a hint on where to look for the underlying cause.

rediar (402)

@Codejira I understand why it errored, I don't understand why something became none. Also, it is not just "so" that turns into None, last time it was I and it seems to change with every run. I already tried debugging (like the code you gave me), and didn't work. Thanks for trying though, I'll give ya an upvote.

PattanAhmed (1246)

@rediar Hi,
Is your error solved?

PattanAhmed (1246)

@rediar Ok.
Read this, you might understand.
Click here

Scroll down until you reach Section called

If this isn't helped you then, Comment below!

Hope this helps
Please mark my answer if this helps

rediar (402)

@PattanAhmed You clearly did not look into my problem. I know what list indexes are and how they work.

Coder100 (10843)

Never knew python was static


rediar (402)

@Coder100 Why does that image show python is static?

Coder100 (10843)

um, well, im assuming word: str means the typescript word: string @rediar