troubles with list.append()

Joe frostjoe at hotmail.com
Sat Sep 8 15:33:14 EDT 2001


I'm having some difficulties with appending
a list to a list.  The code works how I want
it to if used within the the interpreter.
However, if it's invoked from the command
line it fills patch_listing with the last line
of the opened pipe.

Any ideas....

Here's the code I'm using

f = os.popen('/usr/local/bin/ssh ' + target + ' /bin/showrev -p', 'r')

patch = ['', {'obsoletes': None, 'requires': None, 'incompatibles':
None, 'packages': None}]
patch_listing = []

while 1:
	line = string.split(f.readline()[:-1])
	if not line: break # Break at EOF
	
	patch[0] = line[1]
	patch[1]['obsoletes'] =
line[line.index('Obsoletes:')+1:line.index('Requires:')]
	patch[1]['requires'] =
line[line.index('Requires:')+1:line.index('Incompatibles:')]
	patch[1]['incompatibles'] =
line[line.index('Incompatibles:')+1:line.index('Packages:')]
	patch[1]['packages'] = line[line.index('Packages:')+1:]
	
	patch_listing.append(patch)


Printing patch_listing after the while loop
shows it filled with all of the same entries.
Printing it within the while loop shows it
growing as I expect it.


Joe Frost



More information about the Python-list mailing list