如何循环执行我的函数多次=在number_virtuals
中输入数字?
这是我的代码:
import ipaddress
import sys
import re
dataList = []
def CollectData():
''' this fuction will be used to collect input from user'''
number_virtuals = input (" How many virtuals are you requesting? ")
realSerName = input("Please Enter Virtual Name: ")
realTCPport = input("Please Enter Virtual TCP port :")
serName = input("Please Enter Server name, port and IP(format: oser500522:443:172.17.5.1):")
# dataCenter = input("Please Enter Data Center: Please")
dataList.append({"number_virtuals": number_virtuals, "realSerName": realSerName, "realTCPport": realTCPport, "serName": serName})
def printconfig(dataList):
print(dataList)
CollectData()
printconfig(dataList)
有人可以帮我吗?
答案 0 :(得分:1)
cicle可能会有所帮助,例如:
for i in range(datalist[0]["number_virtuals"]):
# code to execute as many times
不要忘记声明dataList和返回值!
答案 1 :(得分:1)
import ipaddress
import sys
import re
dataList=[]
def CollectData():
''' this fuction will be used to collect input from user'''
number_virtuals = input (" How many virtuals are you requesting? ")
n = 0
realSerName, realTCPport, serName = [], [], []
while n < int(number_virtuals):
realSerName += input("Please Enter Virtual Name: ")
realTCPport += input("Please Enter Virtual TCP port :")
serName += input("Please Enter Server name, port and IP(format: oser500522:443:172.17.5.1):")
n+=1
# dataCenter = input("Please Enter Data Center: Please")
dataList.append({"number_virtuals": number_virtuals, "realSerName": realSerName, "realTCPport": realTCPport, "serName": serName})
def printconfig(dataList):
print(dataList)
CollectData()
printconfig(dataList)
答案 2 :(得分:1)
您需要多少个虚拟机? 1个 请输入虚拟名称:nifi-prod-pci 请输入虚拟TCP端口:8081 8082 请输入服务器名称,端口和IP(格式:oser500522:443:172.17.5.1):oser502687:8081:156.92.161.232 oser50268956.92.161.233:8081 [{'number_virtuals':'1','realSerName':['n','i','f','i','-','p','r','o','d' ,'-','p','c','i'],'realTCPport':['8','0','8','1','','8','0', '8','2'],'serName':['o','s','e','r','5','0','2','6','8', '7',':','8','0','8','1',':','1','5','6','。','9','2 ','。','1','6','1','。','2','3','2','','5','6','。',' 9','2','。','1','6','1','。','2','3','3',':','8','0' ,“ 8”,“ 1”,“']}]
答案 3 :(得分:0)
现在正在工作,但是如何只从一个循环中收集数据。我需要为每个循环收集所有数据:
import ipaddress
import sys
import re
dataList=[]
def CollectData():
''' this fuction will be used to collect input from user'''
number_virtuals = input (" How many virtuals are you requesting? ")
n = 0
while n < int(number_virtuals):
realSerName = input('Please Enter Virtual Name: ')
realTCPport = input("Please Enter Virtual TCP port :")
serName = input("Please Enter Server name, port and IP(format: oser500522:443:172.17.5.1):")
n+=1
dataList.append({"number_virtuals": number_virtuals, "realSerName": realSerName, "realTCPport": realTCPport, "serName": serName})
def printconfig(dataList):
print(dataList)
CollectData()
printconfig(dataList)
How many virtuals are you requesting? 2
Please Enter Virtual Name: test-lap
Please Enter Virtual TCP port :443
Please Enter Server name, port and IP(format: oser500522:443:172.17.5.1):osr1234
Please Enter Virtual Name: zenk-233
Please Enter Virtual TCP port :7887898
Please Enter Server name, port and IP(format: oser500522:443:172.17.5.1):kkkkkkkkk
[{'number_virtuals': '2', 'realSerName': 'zenk-233', 'realTCPport': '7887898', 'serName': 'kkkkkkkkk'}]