Marwane
Marwane

Reputation: 13

How to pass an array of powershell to a python script

I am actually trying to give an arrayList (System.Collections.ArrayList) in a powershell script to a python script like this :
Powershell script

    $exampleArray= New-Object System.Collections.ArrayList
    $tabChemins.Add("test1") | Out-Null
    $tabChemins.Add("test2") | Out-Null
    $tabChemins.Add("test3") | Out-Null
    python.exe .\exampleScriptPython.py $exampleArray

Python script : (I don't want to cycle through all the elements using a loop to create my list.)


    import sys
    print(sys.argv[1])
    print(sys.argv[2])
    print(sys.argv[3])


It gives me element by element but I want them in only one element, Output :
test1
test2
test3

Ideal output :
['test1','test2','test3']

Upvotes: 1

Views: 810

Answers (1)

goodvibration
goodvibration

Reputation: 6206

Seems like you can simply use the array sys.argv[1:] for whatever it is that you want to do.

And if you want to pass it to a function as separate arguments, then I believe that *sys.argv[1:] would do the job.

Upvotes: 1

Related Questions