IWETHEY v. 0.3.0 | TODO
1,095 registered users | 0 active users | 0 LpH | Statistics
Login | Create New User
IWETHEY Banner

Welcome to IWETHEY!

New Oh, I underrstand class/object methods
The classmethod() thing was just an example of decorator. Other good examples include foo=synchronized(foo), foo=traced(foo), foo=remote(machine_name, foo) and so on. Any thing that modifies the way function executes.

BTW, FuManChu surreptitiously folded function attributes in there as well. I wonder if python is concistant enough that you can write not only

def foo():
pass


foo.author = "me"


but also

1.owner = "me"

or

"blah".speaker = "me"


:)

--

"...was poorly, lugubrious and intoxicated."

-- Patrick O'Brian, "Master and Commander"
New You can't do that to builtins yet
But you can usually subclass builtins and get what you want.

PythonWin 2.3.2 (#49, Oct 2 2003, 20:02:00) [MSC v.1200 32 bit (Intel)] on win32.
Portions Copyright 1994-2001 Mark Hammond (mhammond@skippinet.com.au) - see 'Help/About PythonWin' for further copyright information.
>>> "thing".x = 0
Traceback (most recent call last):
File "<interactive input>", line 1, in ?
AttributeError: 'str' object has no attribute 'x'
>>> a = "thing"
>>> a.x = 0
Traceback (most recent call last):
File "<interactive input>", line 1, in ?
AttributeError: 'str' object has no attribute 'x'
>>> class Thing(str):
... \tpass
...
>>> a = Thing()
>>> a.x = 0
>>> a.x
0
"Despite the seemingly endless necessity for doing
so, it's actually not possible to reverse-engineer intended invariants
from staring at thousands of lines of code (not in C, and not in
Python code either)."

Tim Peters on python-dev
New You can do that in Ruby
You can't do it exactly like you suggested - since there is no method named owner on the number 1, you cannot call that method. You have to create the method first. This works:
\nclass Fixnum;\n  attr_accessor :owner;\nend\n\n1.owner = "me";\nputs 1.owner;\n

Cheers,
Ben
To deny the indirect purchaser, who in this case is the ultimate purchaser, the right to seek relief from unlawful conduct, would essentially remove the word consumer from the Consumer Protection Act
- [link|http://www.techworld.com/opsys/news/index.cfm?NewsID=1246&Page=1&pagePos=20|Nebraska Supreme Court]
     Python decorator proposal - (FuManChu) - (10)
         as a non python user, whats wrong with the old way? -NT - (boxley) - (1)
             Not really wrong, just annoying - (FuManChu)
         I don't understand the example :( - (Arkadiy) - (5)
             classmthod - (FuManChu) - (4)
                 A more concrete example from Ruby - (ben_tilly) - (3)
                     Oh, I underrstand class/object methods - (Arkadiy) - (2)
                         You can't do that to builtins yet - (FuManChu)
                         You can do that in Ruby - (ben_tilly)
         An update on the proposed change - (ChrisR) - (1)
             Why, yes, he did. :) - (FuManChu)

Not straight enough to make a perfect structure.
106 ms