Wiki Example Does Not Run

I'm working on understanding how list controls work, so I copied the
example from the Wiki page, "WriteItYourself", and brought it up to date. I
thought.

   However, it will not run. The error I get is that:

   File "listctrl.py", line 51, in __init__
     self.Bind(wx.EVT_BUTTON, self.OnAdd, b1)
AttributeError: 'MyDialog' object has no attribute 'OnAdd'

   I'm not seeing the error. A clue stick would help.

Thanks,

Rich

listctrl.py (2.83 KB)

···

--
Richard B. Shepard, Ph.D. | Author of "Quantifying Environmental
Applied Ecosystem Services, Inc. (TM) | Impact Assessments Using Fuzzy Logic"
<http://www.appl-ecosys.com> Voice: 503-667-4517 Fax: 503-667-8863

You have an indentation error :slight_smile:

The def for OnAdd (and other methods) is outdented to the same level
as the class def, which means the method is not part of the class
definition. Just make sure all class methods are at the same
indentation level as 'def __init__'.

HTH!

···

On 05/12/05, Rich Shepard <rshepard@appl-ecosys.com> wrote:

   I'm working on understanding how list controls work, so I copied the
example from the Wiki page, "WriteItYourself", and brought it up to date. I
thought.

   However, it will not run. The error I get is that:

   File "listctrl.py", line 51, in __init__
     self.Bind(wx.EVT_BUTTON, self.OnAdd, b1)
AttributeError: 'MyDialog' object has no attribute 'OnAdd'

   I'm not seeing the error. A clue stick would help.

--
John.

John,

   Sigh. Thanks. I never make this type of error in C. :frowning:

Rich

···

On Mon, 5 Dec 2005, John Fouhy wrote:

The def for OnAdd (and other methods) is outdented to the same level as the
class def, which means the method is not part of the class definition. Just
make sure all class methods are at the same indentation level as 'def
__init__'.

--
Richard B. Shepard, Ph.D. | Author of "Quantifying Environmental
Applied Ecosystem Services, Inc. (TM) | Impact Assessments Using Fuzzy Logic"
<http://www.appl-ecosys.com> Voice: 503-667-4517 Fax: 503-667-8863

Sunday, December 4, 2005, 10:41:56 PM, Rich Shepard wrote:

   I'm working on understanding how list controls work, so I copied the
example from the Wiki page, "WriteItYourself", and brought it up to date. I
thought.

   However, it will not run. The error I get is that:

   File "listctrl.py", line 51, in __init__
     self.Bind(wx.EVT_BUTTON, self.OnAdd, b1)
AttributeError: 'MyDialog' object has no attribute 'OnAdd'

   I'm not seeing the error. A clue stick would help.

Increase the indentation of lines 60~74. They are not currently
methods of MyDialog as they should.

-- tacao

No bits were harmed during the making of this e-mail.

I bet you never had a buffer overflow in python, though :slight_smile:

···

On 05/12/05, Rich Shepard <rshepard@appl-ecosys.com> wrote:

John,

   Sigh. Thanks. I never make this type of error in C. :frowning:

Rich Shepard wrote:

  Sigh. Thanks. I never make this type of error in C. :frowning:

No, you make brace errors instead :wink:

I wonder if you're the only person in the world that makes more scope errors in Python than C!

You really should consider using 4 spaces, rather than 2, for your indentation. It would make this kind of thing more obvious, and make your code the same as (almost) everyone else's.

-Chris

···

--
Christopher Barker, Ph.D.
Oceanographer
                                          
NOAA/OR&R/HAZMAT (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception

Chris.Barker@noaa.gov

John,

   Yes, thank you. It was a long day and I just did not watch what I was doing
when I cut from the Wiki page and copied to the editor. The number of spaces
of indentation would not have mattered.

Rich

···

On Mon, 5 Dec 2005, John Fouhy wrote:

The def for OnAdd (and other methods) is outdented to the same level as the
class def, which means the method is not part of the class definition. Just
make sure all class methods are at the same indentation level as 'def
__init__'.

HTH!

--
Richard B. Shepard, Ph.D. | Author of "Quantifying Environmental
Applied Ecosystem Services, Inc. (TM) | Impact Assessments Using Fuzzy Logic"
<http://www.appl-ecosys.com> Voice: 503-667-4517 Fax: 503-667-8863