custom event problem with simplified example code

Tim Roberts <timr <at> probo.com> writes:

or maybe better is:

    class CustomContextMenuEvent(wx.PyCommandEvent):
        def __init__(self, id, pos, menu_item_list=):
            wx.PyCommandEvent.__init__(self, myEVT_CUSTOM_CONTEXT_MENU, id)
            self.pos = pos
            self.menu_item_list = menu_item_list[:]

Thanks, Tim. Let me see if I've got this straight:
So, I was reusing the same object because I was assigning the list object
to self.menu_item_list, which by default in Python creates an object reference.
By assigning a sliced version of the list, Python must create a new list object
to represent it, and my problem goes away. Right?
(the problem does go away, btw)

> I should also point out that it's not just my custom event that seems to be
> getting reused in this way. If you look at the address of the
> wx.EVT_CONTEXT_MENU with each right click, you see that its address is the
> same every time too.
>

No. It's just that the objects happen to be created at the same address
each time.

OK, that's comforting. I had hoped that was the case, but I had assumed it
unlikely that the same memory would be reused every time. I suppose if there
are no other mechanisms in the application that would request a block of memory
the same size (or smaller) as the freed event, the underlying memory manager for
the python process is likely to return the same block each time.

Thanks, Tim!
Tim