list assignment/reference

Hi,
I am a newbie at (wx)python so don't flame me if I post this question
at the wrong place. Just redirect me. TIA.
I want to use a list for wx.checkbox assignment such that in my loop
like:
for x in range(0,y):
     checkbox[x] = str(x)
self.check[bak] = wx.CheckBox(self, -1, caption)
            s
However this yields an error (not am wxpython error). I need to create/
allocate checkbox first. Putting checkbox = [] before the for loop
will not to this, so currently I am using
checkbox =[None, None, None, None, None, None...... and so on
Is there an easier way to do thing (referral to another group also
appreciated).?

Samuel

Hi,

···

On Mon, Mar 1, 2010 at 8:08 AM, samuel en <samuel110011@gmail.com> wrote:

Hi,
I am a newbie at (wx)python so don't flame me if I post this question
at the wrong place. Just redirect me. TIA.
I want to use a list for wx.checkbox assignment such that in my loop
like:
for x in range(0,y):
checkbox = str(x)
self.check[bak] = wx.CheckBox(self, -1, caption)
s
However this yields an error (not am wxpython error). I need to create/
allocate checkbox first. Putting checkbox = before the for loop
will not to this, so currently I am using
checkbox =[None, None, None, None, None, None...... and so on
Is there an easier way to do thing (referral to another group also
appreciated).?

If you 'checkbox' is a list, then just use append

checkbox.append(str(x))

Your getting an error because the list hasn't been expanded to have
the indexes your trying to access in the loop.

Cody

Thanks Cody,

Put in the right direction by your advise I changed checkbox = []
to checkbox = (), this works too. I do not understand why, but hey I
am really new to Python.

Hi,

Thanks Cody,

Put in the right direction by your advise I changed checkbox =
to checkbox = (), this works too. I do not understand why, but hey I
am really new to Python.

This has nothing to do with the advise I gave??

checkbox = # This is declaring checkbox as a list()
checkbox = () # This is declaring checkbox as a tuple()

Tuples are immutable (meaning they cant be modified after they are
created). So that will definitely not work if your trying to add
things to it later.

I am not sure as to what you are trying to do above it looks like your
trying to create a list of strings?

checkbox =
for x in range(0, y):
    checkbox.append(str(x))

May want to start off with some of the tutorials at python.org

http://groups.google.com/group/comp.lang.python/topics

Cody

···

On Mon, Mar 1, 2010 at 8:39 AM, samuel en <samuel110011@gmail.com> wrote:

Hi,
I am a newbie at (wx)python so don't flame me if I post this question
at the wrong place.

Welcome. There is not much flaming that happens here, maybe just an
occasional good natured LMGTFY. :smiley:

Just redirect me. TIA.

I want to use a list for wx.checkbox assignment such that in my loop
like:
for x in range(0,y):
checkbox = str(x)
self.check[bak] = wx.CheckBox(self, -1, caption)
s

Tip: name things such that when you (or others) read the code, it is
clear what things are. E.g., is "checkbox" a wx.CheckBox, or is it a
list? If it is a list of the wx.CheckBoxes you will use, how about
naming it checkBoxList? Then how about naming the actual CheckBoxes
self.myCheckBox or something like that.

However this yields an error (not am wxpython error).

When posting a question to any list and you get an error, copy and
paste that exact error into your message.

Is there an easier way to do thing (referral to another group also
appreciated).?

For basic Python questions like adding items to a list, the Python
tutor list is really good:
Tutor Info Page. But Googling for the
error you got may give you some insight about what the problem is,
too. And reading tutorials, etc.

Good luck,
Che

···

On Mon, Mar 1, 2010 at 9:08 AM, samuel en <samuel110011@gmail.com> wrote:

Thanks everyone for the tips.
As a newbie, I am amazed how beautiful Python is and although I
obviously need more time at manuals I am learning along the way,
writing a big application with ease for fun.