Thanks,
Others have provided the correction, but I have a few comments. You
said in the first post:
However, even if I make the variables/list global, wx does not allow
me to append (fill) the list inside of the def __init (self, event) function.
Is there a way to get around this?
This suggests that you assumed wxPython was putting a restriction on
what you "should" be able to do. But, later you provided the error
you got:
I have attached a small sample app with an example. Everything is OK
except the DataList list. I get the same error message in both
windows and linux platforms: "TypeError: 'builtin_function_or_method'
object is unsubscriptable".
First, it's good to give the *whole* error message, not just the last
line--or at least the last five or so lines, since it will point out
the offending line in your code.
Next, if you Google "Python TypeError" you can get to the Python docs and find:
exception TypeError
Raised when an operation or function is applied to an object of
inappropriate type. The associated value is a string giving details
about the type mismatch.
This should tip you off that the problem is not a wxPython problem,
nor anything having to do with Windows or Linux platforms, but a
problem with your code, that is, an error in the use of Python. In
fact, it's a type error, and it tells you what error you've made,
which is you have tried to treat a function--append()--as though it
were a subscriptable object like a list or a tuple in which you can
refer to an item in it with brackets (like mylist[3] is the third item
in mylist).
The point is: don't assume that just because you can't get what you
want that wxPython is preventing a reasonable action. The error
messages are your absolute best friend in debugging your code, which
*will* have many mistakes on your (or anyone's) part. I always find
it much worse when my code doesn't do what I want but runs without
errors--because errors usually quickly show me what I did wrong. It
should give the offending line, too, as I said.
A few other comments on your code:
global trial
global click
Use of globals is generally discouraged in Python, I think because you
are putting names into the global namespace and it can conflict with
names within functions. What you could do instead is to make trial
and click child objects of the frame, so make them self.trial and
self.click. Then they can be accessed from any function within the
Frame's class.
def OnAnswer(self, event):
global trial
global click
I'm not sure (since I never use globals) but isn't this redundant to
declare them again?
trial = trial + 1
click = click + 2
That can be, if you prefer (you might know already):
trial += 1
click += 1
Che
···
On Wed, Jan 19, 2011 at 11:25 AM, SDL <asimov1966@gmail.com> wrote: