Barry> attributes, but decorators can also do the trick in a nasty way: Barry> Barry> def foobar [ Barry> lambda f: f.author = 'Guido van Rossum', Barry> lambda f: f.deprecated = True, Barry> classmethod] (self, arg): Barry> # Now what? Alex> Not necessarily all that nasty: Alex> def foobar [ with_attributes( Alex> author="Guido van Rossum", Alex> deprecated=True), Alex> classmethod] (cls, args): Alex> pass Both cases demonstrate why I don't like the decorator-before-args option. Where are the args? Like I said in an earlier post most of the time I look at a function def wanting a quick reminder how to call it. If the argument list doesn't at least start on the same line as the def I think that will be tougher. Alex> with a built-in 'with_attributes' equivalent to: Alex> def with_attributes(f, **kwds): Alex> for k, v in kwds.iteritems(): Alex> setattr(f, k, v) Alex> return f Not quite. It has to be written as a function which returns another function, e.g.: def attrs(**kwds): def decorate(f): f.__dict__.update(kwds) return f return decorate Skip
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4