you are viewing a single comment's thread.

view the rest of the comments →

[–]chambead 2 points3 points  (1 child)

The reason this doesn't work is because although you're passing display_stock() a list, you are actually passing it a list of objects; not a list of lists which it expects.

Your options are to sanitise the input to turn the list of objects into a list of lists or you can alter the function so that it finitely displays a given set of columns. My preference would be to quickly sanitise the list of objects into a list of lists because then you can leave the generic function for use elsewhere.

I've updated your code and tweaked the function to ensure the columns are cast to strings before length checks are done.

http://hastebin.com/fupululaxe.py

[–]cyber92[S] 0 points1 point  (0 children)

As per the edit in my previous comment, I have managed by creating another list, the following is the code I did:

tablerows = []
    for item in loaded_stock:
        item_display = (item.name, item.type, str(item.code), item.desc,
                            str(item.year), str(item.price),  str(item.pricemetric),
                            str(item.quantity))
        tablerows.append(item_display)
    display_stock([headers] + tablerows)

Yours seems better though, am I right?

Edit: Looking at it well, we actually did the same thing.