[BangPypers] Multiple return values from a function : Where to draw the line ?

2014-05-23 Thread Mandar Vaze / मंदार वझे
Currently I came across the code that returned 9 values (return statement spanned 5 lines due to pep8 limitation of 79 characters per line) The function returns various values that are used by the template to render HTML To give you an idea - consider following two code snippets : (This is just

Re: [BangPypers] Multiple return values from a function : Where to draw the line ?

2014-05-23 Thread shankha
Write code which is readable and then put in effort to speed things up, if need be. The Code 1 is definitely confusing. Why don't you create a class and fill up the member variables. Much more readable. There is a dis module which allows you to dump assembly code. You can check how many

Re: [BangPypers] Multiple return values from a function : Where to draw the line ?

2014-05-23 Thread Noufal Ibrahim KV
On Fri, May 23 2014, Rohit Chormale wrote: How is it if you use DataContainer class set attributes of that class. Something like, class Data(object): def __init__(self, **kwargs): object.__setattr__(self, 'attribs', kwargs) def __getattr__(self, item): if item in

Re: [BangPypers] Multiple return values from a function : Where to draw the line ?

2014-05-23 Thread Noufal Ibrahim KV
On Fri, May 23 2014, Mandar Vaze / मंदार वझे wrote: Currently I came across the code that returned 9 values (return statement spanned 5 lines due to pep8 limitation of 79 characters per line) The function returns various values that are used by the template to render HTML To give you an

Re: [BangPypers] Multiple return values from a function : Where to draw the line ?

2014-05-23 Thread kracekumar ramaraju
You can use namedtuple. from collections import namedtuple Person = namedtuple('Person', ['foo', 'bar', 'baz']) p = Person(foo='foo', bar='bar', baz='baz') print p.foo 'foo' On Fri, May 23, 2014 at 1:23 PM, Noufal Ibrahim KV nou...@nibrahim.net.inwrote: On Fri, May 23 2014, Rohit Chormale

Re: [BangPypers] Multiple return values from a function : Where to draw the line ?

2014-05-23 Thread Noufal Ibrahim KV
On Fri, May 23 2014, kracekumar ramaraju wrote: You can use namedtuple. from collections import namedtuple Person = namedtuple('Person', ['foo', 'bar', 'baz']) p = Person(foo='foo', bar='bar', baz='baz') [...] Much better although with namedtuple, the attributes are fixed aren't they? I

Re: [BangPypers] Multiple return values from a function : Where to draw the line ?

2014-05-23 Thread kracekumar ramaraju
Yes. Attributes are fixed. The advantage over dictionary is ease of access like p.foo rather than p['foo'] or p.get('foo'). On Fri, May 23, 2014 at 1:34 PM, Noufal Ibrahim KV nou...@nibrahim.net.inwrote: On Fri, May 23 2014, kracekumar ramaraju wrote: You can use namedtuple. from

Re: [BangPypers] Multiple return values from a function : Where to draw the line ?

2014-05-23 Thread Rohit Chormale
R u sure @ 'ease of access' or is it 'ease of writing'? On Fri, May 23, 2014 at 1:43 PM, kracekumar ramaraju kracethekingma...@gmail.com wrote: Yes. Attributes are fixed. The advantage over dictionary is ease of access like p.foo rather than p['foo'] or p.get('foo'). On Fri, May 23, 2014

Re: [BangPypers] Multiple return values from a function : Where to draw the line ?

2014-05-23 Thread kracekumar ramaraju
Rohit Probably ease of writing may be right here. On Fri, May 23, 2014 at 1:46 PM, Rohit Chormale rohitchorm...@gmail.comwrote: R u sure @ 'ease of access' or is it 'ease of writing'? On Fri, May 23, 2014 at 1:43 PM, kracekumar ramaraju kracethekingma...@gmail.com wrote: Yes.

Re: [BangPypers] Multiple return values from a function : Where to draw the line ?

2014-05-23 Thread Noufal Ibrahim KV
On Fri, May 23 2014, kracekumar ramaraju wrote: Rohit Probably ease of writing may be right here. It's also more future proof. An attribute can be replaced by a property which implements access controls and other things without breaking API contracts. It's harder to do that while

Re: [BangPypers] Multiple return values from a function : Where to draw the line ?

2014-05-23 Thread Navin Kabra
Mandar Vaze / मंदार वझे mandarv...@gmail.com writes: Code 1: ... return dict(fname=fname, lname=lname, saluation=salutation, gender=gender, addr1=addr1, addr2=addr2, city=city, state=state, country=country) First of all, both functions are returning a single value, a

Re: [BangPypers] Multiple return values from a function : Where to draw the line ?

2014-05-23 Thread Mandar Vaze / मंदार वझे
On Fri, May 23, 2014 at 5:26 PM, Navin Kabra na...@smriti.com wrote: Mandar Vaze / मंदार वझे mandarv...@gmail.com writes: Code 1: ... return dict(fname=fname, lname=lname, saluation=salutation, gender=gender, addr1=addr1, addr2=addr2, city=city, state=state,