why no user-def. attributes?

Discussion in 'Python' started by Guest, Sep 2, 2005.

  1. Guest

    Guest Guest

    I appologize in advance for stupid question, which is:
    why are user-defined attributes not allowed for builtin types?
    [I guess I undestand why *instances* cannot have them (e.g. then every
    dict would have a dict which would have a dict..), but this is a
    different question]

    I can imagine several answers, so I put here those that don't seem
    satisfactory to me :)

    1. You can subclass, eg.
    class my_int(int): pass
    and then do whatnot, like my_int.__getitem__=some_vicious_function

    Here the problem is just that it's easier to write 4 than
    my_int(4), or "ha" than my_string("ha") etc.

    2. You would probably want to add new methods, so why don't you
    define a function and then write e.g. dowhatIwant([1,2,3]) instead of
    [1,2,3].dowhatIwant()

    That's OK, except for the convenience of special methods like __add__ or
    __iter__

    3. It would lead to a confusing code

    Oops, maybe I shouldn't have written this one..


    Anyway, please let me know the true reason (which is perhaps technical)


    Best whishes
    Paul
     
    Guest, Sep 2, 2005
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jiong Feng
    Replies:
    0
    Views:
    905
    Jiong Feng
    Nov 19, 2003
  2. Mr. SweatyFinger
    Replies:
    2
    Views:
    2,129
    Smokey Grindel
    Dec 2, 2006
  3. Sean Ross
    Replies:
    3
    Views:
    139
    Aredridel
    Dec 25, 2003
  4. Replies:
    7
    Views:
    175
  5. planetthoughtful

    Newbie: def must come before call to def?

    planetthoughtful, Mar 12, 2007, in forum: Ruby
    Replies:
    4
    Views:
    139
    Pit Capitain
    Mar 12, 2007
Loading...

Share This Page