Problem with python 3.6.3 and wxPython Phoenix 4.0.0b2.

Hi all,
how can i to fix this sample code ? See attachment.
I use python 3.6.3 and wxPython Phoenix 4.0.0b2.
Small precision, I do not master python 3.x.
ERROR :
File “C:\wx.ListCtrl virtual.py”, line 80, in
app.MainLoop()
File “C:\Users\toto\AppData\Local\Programs\Python\Python36-32\Lib\site-packages\wx\core.py”, line 2085, in MainLoop
rv = wx.PyApp.MainLoop(self)
File “C:\wx.ListCtrl virtual.py”, line 60, in Sort
self.items.sort(lambda x,y: cmp(x[idx],y[idx]))
builtins.TypeError: must use keyword argument for key function

Thank by advance.

wx.ListCtrl.py (1.8 KB)

The sort method Python 3 no longer uses a cap function. Instead, you specify the “key” function that returns the thing to be sorted:

self.items.sort( key=lambda x: x[idx] )

···

On Oct 29, 2017, at 7:53 AM, factory2pixel@gmail.com wrote:

how can i to fix this sample code ? See attachment.
I use python 3.6.3 and wxPython Phoenix 4.0.0b2.
Small precision, I do not master python 3.x.
ERROR :
File “C:\wx.ListCtrl virtual.py”, line 80, in
app.MainLoop()
File “C:\Users\toto\AppData\Local\Programs\Python\Python36-32\Lib\site-packages\wx\core.py”, line 2085, in MainLoop
rv = wx.PyApp.MainLoop(self)
File “C:\wx.ListCtrl virtual.py”, line 60, in Sort
self.items.sort(lambda x,y: cmp(x[idx],y[idx]))
builtins.TypeError: must use keyword argument for key function


Tim Roberts, timr@probo.com
Providenza & Boekelheide, Inc.

It’s perfect.

    if self.flg_sort == "sm_up":
        # self.items.sort(lambda x,y: cmp(x[idx],y[idx]))
        self.items.sort( key=lambda x: x[idx] )
            
    else:
        # self.items.sort(lambda y,x: cmp(x[idx],y[idx]))            
        self.items.reverse()
        self.flg_sort = "sm_down"

Tim, thank you very much.