Search Results

Search found 3 results on 1 pages for '007brendan'.

Page 1/1 | 1 

  • What to put in a python module docstring?

    - by 007brendan
    Ok, so I've read both PEP 8 and PEP 257, and I've written lots of docstrings for functions and classes, but I'm a little unsure about what should go in a module docstring. I figured, at a minimum, it should document the functions and classes that the module exports, but I've also seen a few modules that list author names, copyright information, etc. Does anyone have an example of how a good python docstring should be structured?

    Read the article

  • Should I use a metaclass, class decorator, or override the __new__ method?

    - by 007brendan
    Here is my problem. I want the following class to have a bunch of property attributes. I could either write them all out like foo and bar, or based on some other examples I've seen, it looks like I could use a class decorator, a metaclass, or override the __new__ method to set the properties automagically. I'm just not sure what the "right" way to do it would be. class Test(object): def calculate_attr(self, attr): # do calculaty stuff return attr @property def foo(self): return self.calculate_attr('foo') @property def bar(self): return self.calculate_attr('bar')

    Read the article

  • Can I create class properties during __new__ or __init__?

    - by 007brendan
    I want to do something like this. The _print_attr function is designed to be called lazily, so I don't want to evaluate it in the init and set the value to attr. I would like to make attr a property that computes _print_attr only when accessed: class Base(object): def __init__(self): for attr in self._edl_uniform_attrs: setattr(self, attr, property(lambda self: self._print_attr(attr))) def _print_attr(self, attr): print attr class Child(Base): _edl_uniform_attrs = ['foo', 'bar'] me = Child() me.foo me.bar #output: #"foo" #"bar"

    Read the article

1