10

How do you do an os.path.join with an array in python? Basically, I want to be able to run that command with an array as an argument. Any help is highly appreciated.

1 Answers1

23

By array I assume you mean list.

os.path.join(*parts)

The * takes a list (or similar object) and expands it into parameters. Be careful using it, in many situations it will make your code harder to read. But here is makes sense.

Winston Ewert
  • 44,070
  • 10
  • 68
  • 83
  • As an aside, you can also use function(**kwargs) to pass a dictionary as a set of keyword arguments. You can also use both forms in a function definition to get any extra arguments, or any extra keyword arguments to the function. You can even use them together. – Matthew Schinckel Nov 27 '10 at 07:49