list index out of range when trying to access a specific list item
Question: I'm very new to Python and can't figure out why this simple code doesn't work:

I have a string (a message like `handposition/506.83047/388.1101/703.2166`
from my websocket client) with `/` as separator and want to split it into a
list:

    
    
    coordinates = msg.split('/')
    

I can print the list with:

    
    
    print(coordinates)
    

and get this:

    
    
    ['handposition', '495.0279', '443.24762', '976.6502']
    

Everything works until I try to access the second element in the list with:

    
    
    print(coordinates[1])
    

I get this error message:

    
    
    File "mouse_server.py", line 19, in onMessage
      print(coordinates[2])
      exceptions.IndexError: list index out of range
    

Whats wrong with `print(coordinates[1])`?

# Update 1

Here is the full code:

    
    
    from autobahn.twisted.websocket import WebSocketClientProtocol, \
                                           WebSocketClientFactory
    from pymouse import PyMouse
    
    mo = PyMouse()
    
    class MyClientProtocol(WebSocketClientProtocol):
    
        def onConnect(self, response):
            print("Server connected: {0}".format(response.peer))
    
        def onOpen(self):
            print("WebSocket connection open.")
    
        def onMessage(self, msg, isBinary):
            coordinates = msg.split('/')
            print(coordinates)
            print(coordinates[1])
    
        def onClose(self, wasClean, code, reason):
            print("WebSocket connection closed: {0}".format(reason))
    
    
    if __name__ == '__main__':
    
        import sys
    
        from twisted.python import log
        from twisted.internet import reactor
    
        log.startLogging(sys.stdout)
    
        factory = WebSocketClientFactory("ws://localhost:4343", debug = False)
        factory.protocol = MyClientProtocol
    
        reactor.connectTCP("127.0.0.1", 4343, factory)
        reactor.run()
    


Answer: Most likely, if you are running this on a bunch of lines, there might be one
input line that does not have all the expected fields. You can print the whole
list before accessing that element and see the last one that appears before
the exception.

