我有以下代码:
from itertools import permutations
import string
output_file = open('list.txt', 'w+')
import sys
sys.stdout = open("list.txt", "w+")
# Enter new brand names to following lists
brand_names = "8x8, AmazonAWS, Checkpoint, Cisco, Citrix, Commvault, Dell, Dell_EMC, Google, Google_Cloud, HPE, Hyland, IBM, IBM_Cloud, Microsoft, Microsoft_Azure, NetApp, Oracle, Pure_Storage, SAP, Thompson_Reuters, Veritas, VMware, Aerohive, Aramark, Bloomberg, BMC, Box, CompuCom, Cybera, Extreme, FireEye, GE, Globoforce, GPSI, Infor, Lux_Research, MetTel, Oracle_Cloud, PAR_Invista, Puppet, Rackspace, Ruckus, Salesforce, SonicWall, SPI, Splunk, Stratix, Supermicro, Tenable, Ultipro, US_Bank, Veeam, VIP"
for group in permutations(['8x8', 'AmazonAWS', 'Checkpoint', 'Cisco', 'Citrix', 'Commvault', 'Dell', 'Dell_EMC', 'Google', 'Google_Cloud', 'HPE', 'Hyland', 'IBM', 'IBM_Cloud', 'Microsoft', 'Microsoft_Azure', 'NetApp', 'Oracle', 'Pure_Storage', 'SAP', 'Thompson_Reuters', 'Veritas', 'VMware', 'Aerohive', 'Aramark', 'Bloomberg', 'BMC', 'Box', 'CompuCom', 'Cybera', 'Extreme', 'FireEye', 'GE', 'Globoforce', 'GPSI', 'Infor', 'Lux Research', 'MetTel', 'Oracle_Cloud', 'PAR_Invista', 'Puppet', 'Rackspace', 'Ruckus', 'Salesforce', 'SonicWall', 'SPI', 'Splunk', 'Stratix', 'Supermicro', 'Tenable', 'Ultipro', 'US Bank', 'Veeam', 'VIP'], 3):
print('_'.join(group))>output_file
output_file.close()
# Python3 code to demonstrate
# to count words in string
# using regex (findall())
import re
# printing original string
print ("The original string is : ")
print "\n"
print("'" + brand_names + "'")
# using regex (findall())
# to count words in string
res = len(re.findall(r'\w+', brand_names))
print "\n"
# printing result
print ("The number of brands are : " + str(res))
print "\n"
我想打印所有的排列可能性,但是这确实打印了可能性的数量,但是它在单独的一行上打印为“真”
你知道为什么会这样吗?你知道我该怎么解决吗
这不是用Python编写文件的方式
你应该做
output_file.write('_'.join(group))
相关问题 更多 >
编程相关推荐