Python 为列表中的项目分配变量,并在打印所需输出时使用这些值

Python 为列表中的项目分配变量,并在打印所需输出时使用这些值,python,Python,我是Python新手,我试图创建一个脚本,为Aruba无线接入点SSID输出一个配置文件 我希望访问点有一个用逗号分隔的单行输入,每个输入将被读取并分配一个唯一的变量,然后在配置脚本中使用/调用该变量 这里棘手的部分是接入点的数量不是固定的,因为它将取决于用户请求。我希望脚本能够容纳任何给定的输入,例如: items = input("Enter the list of devices here: \n") ## AP01,AP05,AP06,AP10,AP15 ## The list num

我是Python新手,我试图创建一个脚本,为Aruba无线接入点SSID输出一个配置文件

我希望访问点有一个用逗号分隔的单行输入,每个输入将被读取并分配一个唯一的变量,然后在配置脚本中使用/调用该变量

这里棘手的部分是接入点的数量不是固定的,因为它将取决于用户请求。我希望脚本能够容纳任何给定的输入,例如:

items = input("Enter the list of devices here: \n") ## 
AP01,AP05,AP06,AP10,AP15 ## The list number is unknown as it varies depending on the need
ap1 = items[0]
ap2 = items[1]
ap3 = items[2]
.
.
.
.
apn = items[n]

apconf1 = "ap-name" + " " + ap1\n + "vap-profile Test101_vprof"
apconf1 = "ap-name" + " " + ap2\n + "vap-profile Test101_vprof"
apconf1 = "ap-name" + " " + ap3\n + "vap-profile Test101_vprof"
.
.
.
.
apconfn = "ap-name" + " " + apn\n + "vap-profile Test101_vprof"
print(apconf1)
print(apconf2)
print(apconf3)
.
.
.
.
print(apconfn)
并输出如下内容:

items = input("Enter the list of devices here: \n") ## 
AP01,AP05,AP06,AP10,AP15 ## The list number is unknown as it varies depending on the need
ap1 = items[0]
ap2 = items[1]
ap3 = items[2]
.
.
.
.
apn = items[n]

apconf1 = "ap-name" + " " + ap1\n + "vap-profile Test101_vprof"
apconf1 = "ap-name" + " " + ap2\n + "vap-profile Test101_vprof"
apconf1 = "ap-name" + " " + ap3\n + "vap-profile Test101_vprof"
.
.
.
.
apconfn = "ap-name" + " " + apn\n + "vap-profile Test101_vprof"
print(apconf1)
print(apconf2)
print(apconf3)
.
.
.
.
print(apconfn)
然后打印如下内容:

items = input("Enter the list of devices here: \n") ## 
AP01,AP05,AP06,AP10,AP15 ## The list number is unknown as it varies depending on the need
ap1 = items[0]
ap2 = items[1]
ap3 = items[2]
.
.
.
.
apn = items[n]

apconf1 = "ap-name" + " " + ap1\n + "vap-profile Test101_vprof"
apconf1 = "ap-name" + " " + ap2\n + "vap-profile Test101_vprof"
apconf1 = "ap-name" + " " + ap3\n + "vap-profile Test101_vprof"
.
.
.
.
apconfn = "ap-name" + " " + apn\n + "vap-profile Test101_vprof"
print(apconf1)
print(apconf2)
print(apconf3)
.
.
.
.
print(apconfn)
所需输出为:

ap-name AP01
vap-profile Test101_vprof
ap-name AP05
vap-profile Test101_vprof
ap-name AP06
vap-profile Test101_vprof
.
.
.
.
ap-name APn
vap-profile Test101_vprof

如有任何意见,我们将不胜感激。谢谢。

嗨,如果你把这些信息输入到列表中,你的问题就可以解决了

itemlist=[i for i in itemtext.split(',')]

嗨,如果你把这些信息输入到一个列表中,你的问题就可以解决了

itemlist=[i for i in itemtext.split(',')]

items.split(“,”)
是您的首选,并且公认的答案:-)感谢DeepSpace为我指出以前的解决方案。我已经找了好几个星期了。我想我没有使用正确的搜索字符串:)
items.split(“,”)
是您的首选,接受的答案:-)感谢DeepSpace为我指出以前的解决方案。我已经找了好几个星期了。我想我没有使用正确的搜索字符串:)嘿,为什么需要循环,什么也不做?,
itemtext.split(',')
就足够了。我想他需要单独打印,所以如果我们把它打印到列表中,它会更容易变得更动态。嗨,伙计们,感谢大家在这方面的帮助。DeepSpace指出的解决方案对我有效:)@AmilaMGunawardana
itemtext.split(',')==[i for i in itemtext.split(',')]
会让你大吃一惊,哈哈。嘿,为什么需要循环,什么都不做?,
itemtext.split(','))
就足够了。我想他需要单独打印出来,这样如果我们把它列成一个列表,就更容易让它更有活力。嗨,伙计们,感谢大家在这方面的帮助。DeepSpace指出的解决方案对我有效:)@AmilaMGunawardana
itemtext.split(',')==[i for i in itemtext.split(',')]
会让你大吃一惊,哈哈。