oxio oxio - 1 year ago 110
Python Question

Python: Map with class method which requires arguments

I need to call a method for a set of arguments with PyQt5's

, particularly

I have this list of strings,

row = ["a","b","c","d"]

and I need to put every element in a column of the table, except for the first. What I tried is

items = [ QTableWidgetItem(r) for r in row[1:] ]
arguments = zip([rowNumber+1]*(len(row)-1), range(1,len(row)), items)
putItem = lambda x:tableWidget.setItem(*x)
import itertools
itertools.starmap(putItem, arguments)

I also tried with map and no zip of the arguments, but nothing seems to work. I know I could do a
loop on the arguments, but I wanted the "more elegant" map solution.

The main issue is that no information is displayed in the table, though there are no error reports nor warning nor anything.


Answer Source

A loop is more elegant although not as terse, IMHO.

When you create a generator (as with starmap), you have to consume it to execute code. For example, pass it to list().

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download