简体   繁体   English

如何将 powershell 数组传递给 python 脚本

[英]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 脚本中的 arrayList (System.Collections.ArrayList) 提供给 Z23EEEB4347BDD26BDDAFC6 之类的 Z23EEEB4347BDD26BDDZ6 脚本
Powershell script Powershell 脚本

    $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.) Python 脚本:(我不想使用循环遍历所有元素来创建我的列表。)

 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: 它逐个元素地给我,但我只希望它们在一个元素中,Output:
 test1 test2 test3测试1 测试2 测试3

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

Seems like you can simply use the array sys.argv[1:] for whatever it is that you want to do.似乎您可以简单地将数组sys.argv[1:]用于您想做的任何事情。

And if you want to pass it to a function as separate arguments, then I believe that *sys.argv[1:] would do the job.如果您想将它作为单独的 arguments 传递给 function,那么我相信*sys.argv[1:]可以完成这项工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM