每当我使用find_match_column()
函数时,python控制台就会向我显示所有结果都是一个元组,即使它们看起来像是我的列表。如何使结果成为列表?
我的文本文件:https://drive.google.com/file/d/18tYvYs43vA7ib3br1h1VD75OUU5ho1u8/view?usp=sharing
我的代码:
def opentext():
allinstall = open("save_all_install.txt", "r",encoding="UTF-8")
return allinstall
def find_match_column(new_search_words,ent1,ent2):
search_words = ["'Happy'"]
replaced_list = [w.replace("'Happy'", '{}'.format(new_search_words)) for w in search_words]
result = []
for line in opentext():
if any(word in line for word in replaced_list):
# Get the front Publisher Part
k = line.split('\n')[0]
# Get the Position I want for exact Column
entry=k[int('{}'.format(ent1)):int('{}'.format(ent2))].split(',')
# print(entry)
result.append(entry[0])
print(result)
return new_search_words,ent1,ent2 # If not return will show NONE type.
# I want the output should be a list can use for me.
find_match_column("'DisplayName'",17,-5)
find_match_column("'Publisher'",15,-5)
find_match_column("'DisplayVersion'",20,-5)
find_match_column("'InstallDate'",17,-5)
find_match_column("'InstallSource'",19,-5)
find_match_column("'InstallLocation'",21,-5)
示例:如果输入type(find_match_column(XX))
,Python控制台的结果:
<class 'Tuple
答案 0 :(得分:1)
您返回多个值,这些值将始终作为元组返回。
return new_search_words,ent1,ent2 # If not return will show NONE type.
将返回
(new_search_words,ent1,ent2)
您可能想返回结果?
return result