Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Interesting things of 'getattr' and 'setattr'

Reply
Thread Tools

Interesting things of 'getattr' and 'setattr'

 
 
Red Forks
Guest
Posts: n/a
 
      12-15-2009
I don't know it is a feature, or implement detail:

>>> class C(object): pass

....
>>> c = C()
>>> setattr(c, ' ', 3)
>>> getattr(c, ' ')

3
>>> setattr(c, 'with blank', 4)
>>> getattr(c, 'with blank')

4

getattr / setattr seems treat any string as attribute name.
 
Reply With Quote
 
 
 
 
Stefan Behnel
Guest
Posts: n/a
 
      12-15-2009
Red Forks, 15.12.2009 13:19:
> I don't know it is a feature, or implement detail:
>
> >>> class C(object): pass

> ...
> >>> c = C()
> >>> setattr(c, ' ', 3)
> >>> getattr(c, ' ')

> 3
> >>> setattr(c, 'with blank', 4)
> >>> getattr(c, 'with blank')

> 4
>
> getattr / setattr seems treat any string as attribute name.


Feature. We're all adults.

Stefan
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to do INTERESTING things with Ruby sockets??? theosib@gmail.com Ruby 1 03-07-2007 06:05 PM
Re: Lists of lists and tuples, and finding things within them Daniel Nogradi Python 3 11-10-2006 07:57 AM
vs2005 publish website doing bad things, bad things =?Utf-8?B?V2lsbGlhbSBTdWxsaXZhbg==?= ASP .Net 1 10-25-2006 06:18 PM
Some interesting things in cmd.exe Rupert NZ Computing 24 07-20-2004 07:33 AM
Interesting things about Nikon Chuck Digital Photography 32 07-12-2004 03:32 PM



Advertisments