Please help. It's really children's question but I'm at a loss. Why I can't to return array?
There is my script :
groups=[]
host_groups_list = '/usr/local/host_groups.list'
def read_file(file_path):
open_file = open(host_groups_list, "r+")
list=[]
for i in open_file:
list.append(str(i.replace("\n", "")))
print list
return list
goups = read_file(host_groups_list)
print groups
Output :
['hostgroup1', 'hostgroup2']
[]
listas variable name as Mike said. 3.list.append(str(i.replace("\n", ""))),str()is useless here. 4. I think you meanopen_file = open(file_path, "r+")instead ofopen_file = open(host_groups_list, "r+"). 5.groups = with open(''/usr/local/host_groups.list'') as f: [i.strip() for i in f].