[WxPython] NameError: global name 'PyAssertionError' is not defined - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: GUI (https://python-forum.io/forum-10.html) +--- Thread: [WxPython] NameError: global name 'PyAssertionError' is not defined (/thread-1829.html) |
NameError: global name 'PyAssertionError' is not defined - merlem - Jan-27-2017 How may I handle this error message? The PyAssertionError appears when I try to set values into a grid: So I tried to make a try / except statement:try: self.grid.SetCellValue(1, dyn, dystri) except PyAssertionError: print "wrong row or column" Then I get another error message: But I got it a moment before as error name... how is this possible?And from where can I import this error so that it can be handled by try / except? RE: NameError: global name 'PyAssertionError' is not defined - Larz60+ - Jan-27-2017 I'm not a wx programmer, but use tkinter a lot, so the answer I give here may not apply the error indicates that the value of dyn (which I assume is the column number) is out or range. I am assuming that row 1 is valid (but may not be if you haven't used row 0) Try printing out the value of dyn to see what it contains
RE: NameError: global name 'PyAssertionError' is not defined - Yoriz - Jan-27-2017 As mentioned in your previous thread, show a small runnable snippet of code that shows the error. RE: NameError: global name 'PyAssertionError' is not defined - merlem - Jan-28-2017 (Jan-27-2017, 09:38 PM)Larz60+ Wrote: the error indicates that the value of dyn (which I assume is the column number) is out or range. Yes, that's the case, but it's not my question. I know where the PyAssertionError comes from. But where does the NameError comes from? And does it really need a snippet for a (basically theoretical) question why the own errors are not known to python and how to handle this? But I'll prepare one. May take some hours, then I'll send it. RE: NameError: global name 'PyAssertionError' is not defined - Yoriz - Jan-28-2017 Ok I was thinking you wanted help with fixing the error. PyAssertionError is not a built in python error its a wx python specific error, so you need to put wx. infront of it.>>> import wx >>> wx.PyAssertionError <class 'wx._core.wxAssertionError'> RE: NameError: global name 'PyAssertionError' is not defined - merlem - Jan-28-2017 Thanks a lot, Yoritz! With this, it works :-) . ( I wish the wypython docs would give hints to those kind of things, but I can search and search and search and never come across things like that... *sigh*) And, well, as I have spend (wasted) time in it, the code... if ever somebody would be interested how to get such an error in an easy way. import wx, wx.grid class Teilgridpanel(wx.Panel): def __init__(self, parent, id): wx.Panel.__init__(self, parent, id, pos = wx.DefaultPosition, size = wx.DefaultSize, style = wx.TAB_TRAVERSAL|wx.NO_BORDER) self.gridsize = gridsize = (1, 5) self.grid = wx.grid.Grid(self, style=wx.BORDER_SUNKEN) self.grid.CreateGrid(gridsize[0], gridsize[1]) for dyn in range(6): dystri = "x" try: self.grid.SetCellValue(0, dyn, dystri) except PyAssertionError: print "wrong row or column" class Mainframe(wx.Frame): def __init__(self, parent, id, title): wx.Frame.__init__(self, parent, id, title) # und das Datenpanel in seinem BoxSizer self.datenpanel = Teilgridpanel(self, wx.ID_ANY) self.dpbox = dpbox = wx.BoxSizer(wx.HORIZONTAL) dpbox.Add(self.datenpanel, 1, wx.EXPAND) hbox = wx.BoxSizer(wx.HORIZONTAL) hbox.Add(dpbox, 1, wx.EXPAND) self.SetSizerAndFit(hbox) if __name__ == "__main__": app = wx.App(0) mainframe = Mainframe(None, -1, "Mainframe") app.MainLoop() |