You've called any()
with two arguments:
any(filename.endswith('.txt'), filename.endswith('.sm3dump'))
# <----- argument #1 -----> <------- argument #2 ------->
... but it only takes one, which must be an iterable (a list, tuple, etc.):
any([filename.endswith('.txt'), filename.endswith('.sm3dump')])
# <-------------- one list with two elements -------------->
If you wanted to use or
instead, it's straightforward:
filename.endswith('.txt') or filename.endswith('.sm3dump')
A common idiom when using any()
to perform multiple similar tests is to use a list comprehension or generator expression:
any([filename.endswith(ext) for ext in ('.txt', '.sm3dump')])
# <----------------- list comprehension ----------------->
any(filename.endswith(ext) for ext in ('.txt', '.sm3dump'))
# <-------- generator expression (no brackets) -------->
Although in this case, you can actually supply a tuple of strings to str.endswith()
, and it'll check them all:
filename.endswith(('.txt', '.sm3dump'))
Whichever test you use, you need to remember to end your if
statement with a colon:
if filename.endswith(('.txt', '.sm3dump')):
# do something ...