Reputation: 159
I'm trying to call vim from a python script to open multiple files.
files = []
for i in sys.argv[1:]:
files.append(i)
string = " ".join(str(x) for x in files)
call(["vim", string])
when I call ./open.py 11 42 39
it only open one file called "11 42 39".
How to open them as separates files ?
Thank you.
Upvotes: 1
Views: 111
Reputation: 20599
You need to have the seperate files as seperate items in your list:
call(["vim"] + files)
That is because when you pass a list, then each element in the list after the first one is given to vim as a seperate argument. So you are just giving vim the argument "11 42 39"
. The argument will not be split at " " into three seperate arguments.
If you want to see all files at the same time you can also add -o
to the call to vim:
call(["vim", "-o"] + files)
Upvotes: 3