Another "slice indices must be integers or None or have an __index__ method" thread
Question: Trying to debug a Python script, and keep being this error message:

    
    
     Traceback (most recent call last):
        File "<input>", line 3, in <module>
    TypeError: slice indices must be integers or None or have an __index__ method
    

Since the file names have no integers... this doesn't seem to make any sense.
Any suggestions?

    
    
    import os
    inputFolder = "d:\\full"
    outputFolder = "d:\\clean"
    for path, dir, file in os.walk(inputFolder):
        for filename in file:
            if filename.endswith(".jpeg", ".jpg"):
                inputPath = inputFolder + os.sep + filename
                print inputPath
    


Answer: You are misusing
[`str.endswith`](https://docs.python.org/2/library/stdtypes.html#str.endswith).
The second and third* parameters are `start` and `end`, which are used to
index into the string, **not** additional strings to check for. By default
these are both `None`, hence checking the whole string:

    
    
    >>> 'foo'[None:None]
    'foo'
    

This explains the seemingly-confusing error message; Python is trying to check
`filename['.jpg':None].endswith('.jpeg')`, which clearly doesn't make any
sense. Instead, to check for multiple strings, pass _a single tuple_ as the
first parameter:

    
    
    if filename.endswith((".jpeg", ".jpg")):
                       # ^ note extra parentheses
    

Demo:

    
    
    >>> 'test.jpg'.endswith('.jpg', '.jpeg')
    
    Traceback (most recent call last):
      File "<pyshell#0>", line 1, in <module>
        'test.jpg'.endswith('.jpg', '.jpeg')
    TypeError: slice indices must be integers or None or have an __index__ method
    >>> 'test.jpg'.endswith(('.jpg', '.jpeg'))
    True
    

* _(or third and fourth, as`instance.method(arg)` can be written `Class.method(instance, arg)`)_

