By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,898 Members | 1,325 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,898 IT Pros & Developers. It's quick & easy.

why no user-def. attributes?

P: n/a
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
Sep 2 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.