why can't I do something like this:
files = [file for file in ['default.txt'].append(sys.argv[1:]) if os.path.exists(file)]
list.append doesn't return anything in Python:
>>> l = [1, 2, 3]
>>> k = l.append(5)
>>> k
>>> k is None
True
You may want this instead:
>>> k = [1, 2, 3] + [5]
>>> k
[1, 2, 3, 5]
>>>
Or, in your code:
files = [file for file in ['default.txt'] + sys.argv[1:] if os.path.exists(file)]
You could also use itertools.chain if you don't want to duplicate lists.
files = [file for file in itertools.chain(['default.txt'], sys.argv[1:])
if os.path.exists(file)]
importedos? But note: this is a list comprehension... not a generator expression.append()returns a value? Where did you read there? Where did you see any example like that?