getting started

Cameron Simpson cs at zip.com.au
Fri May 25 18:40:22 EDT 2012


On 25May2012 09:37, Dave Angel <d at davea.name> wrote:
| On 05/25/2012 09:12 AM, Harvey Greenberg wrote:
| > elementary ques...I set
| > s.name = ["a","b"]
| > s.value = [3,5]
| >
| > I get error that s is not defined.  How do I define s and proceed to
| > give its attributes?
[...]
| Of course if you told why you want to do it, we might be able to suggest
| a better type for s.

If he's just mucking around to get a feel for the language then there
probably isn't a better type. So a trite subclass of "object" is the go.

Just a brief aside for Harvey:

I spent a brief while confused that this doesn't work:

  o = object()
  o.x = 1

and that I needed to do this:

  class O(object):
    pass
  o = O()
  o.x = 1

until I realised that plain "object", the root of all classes, doesn't
accept arbitrary attributes. But subclasses do.

Cheers,
-- 
Cameron Simpson <cs at zip.com.au> DoD#743
http://www.cskk.ezoshosting.com/cs/

..And in all of Babylonia there was wailing and gnashing of teeth, till
the prophets bade the multitudes get a grip on themselves and shape up.
        - Woody Allen



More information about the Python-list mailing list