I am passing a list from a subprocess
to the parent process and in the parent process I want to add this to an already existing list. I did this:
subprocess_script.py:
def func():
list = []
list.append('1')
list.append('2')
print'Testing the list passing'
print '>>> list:',list
if __name__ == '__main__':
func()
parent_script.py:
list1 = []
list1.append('a')
list1.append('b')
ret = subprocess.Popen([sys.executable,"/Users/user1/home/subprocess_script.py"],stdout=subprocess.PIPE)
ret.wait()
return_code = ret.returncode
out, err = ret.communicate()
if out is not None:
for line in out.splitlines():
if not line.startswith('>>>'):
continue
value = line.split(':',1)[1].lstrip()
list1.extend(value)
print 'Final List: ',list1
But when I execute this I do not get the desired output. The final list that I want should be : ['a','b','1','2']
. But I get ['a', 'b', '[', "'", '1', "'", ',', ' ', "'", '2', "'", ']']
which is wrong. What am I doing wrong here?