Newbie: returning dynamicly built lists (using win32com)
Fredrik Lundh
fredrik at pythonware.com
Tue Jun 6 13:55:48 EDT 2006
Ransom wrote:
> Very newb here, but my question will hopefully be obvious to someone.
> OK, so what is happening is that I am sending a list of data to an
> overly complicated spreadsheet that produces it's own output (in cell
> 32,6). As I loop through multiple test cases, the print statement
> calling into COM for the cell data seems to be printing out results
> just fine. But when I try and put the output from the spreadsheet into
> a dynamic list after the TODO section thusly:
>
> outputlist = []
> outputlist.extend(excel.ActiveSheet.Cells(32,6)
> return outputlist
>
> I get an error like:
> [<win32com.gen_py.Microsoft Excel 9.0 Object Library.Range instance at
> 0x15450880>]
the Cells call returns some kind of internal win32com object, not strings.
Python has two different ways of converting an object to a string of
characters; str() and repr():
http://pyref.infogami.com/str
http://pyref.infogami.com/repr
when you print an object, Python uses str() to do the conversion.
however, when you print a container, the container object's str()
implementation often uses repr() on the members.
to apply str() to all list members, you can simply do:
outputlist = map(str, outputlist)
print outputlist
or
print map(str, outputlist)
or some other variation thereof.
</F>
More information about the Python-list
mailing list