Python置换打印'True'

2024-03-29 09:57:50 发布

您现在位置:Python中文网/ 问答频道 /正文

我有以下代码:

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"

我想打印所有的排列可能性,但是这确实打印了可能性的数量,但是它在单独的一行上打印为“真”

你知道为什么会这样吗?你知道我该怎么解决吗


Tags: toinimportcloudoutputstringnamesgoogle