Re: A question of style (finding item in list of tuples)

2012-05-21 Thread Roy Smith
On Monday, May 21, 2012 9:39:59 AM UTC-4, Jon Clements wrote: > > def experience_text(self): > > return dict(CHOICES).get("self.level", "???") > Haven't used django in a while, but doesn't the model provide a > get_experience_display() method which you could use... Duh, I totally mi

Re: A question of style (finding item in list of tuples)

2012-05-21 Thread Jon Clements
On Monday, 21 May 2012 13:37:29 UTC+1, Roy Smith wrote: > I've got this code in a django app: > > CHOICES = [ > ('NONE', 'No experience required'), > ('SAIL', 'Sailing experience, new to racing'), > ('RACE', 'General racing experience'), > ('GOOD', 'Experienced

Re: A question of style (finding item in list of tuples)

2012-05-21 Thread Tim Chase
On 05/21/12 08:10, Steven D'Aprano wrote: > On Mon, 21 May 2012 08:37:29 -0400, Roy Smith wrote: > > [...] >> The above code works, but it occurs to me that I could use the much >> shorter: >> >> def experience_text(self): >> return dict(CHOICES).get("self.level", "???") >> >> So, the

Re: A question of style (finding item in list of tuples)

2012-05-21 Thread David Lambert
One suggestion is to construct the dictionary first: CHOICES = dict( NONE = 'No experience required', SAIL = 'Sailing experience, new to racing', RACE = 'General racing experience', GOOD = 'Experienced racer', ROCK = 'Rock star' ) def experience_text(self): try:

Re: A question of style (finding item in list of tuples)

2012-05-21 Thread Steven D'Aprano
On Mon, 21 May 2012 08:37:29 -0400, Roy Smith wrote: [...] > The above code works, but it occurs to me that I could use the much > shorter: > > def experience_text(self): > return dict(CHOICES).get("self.level", "???") > > So, the question is, purely as a matter of readability, which

Re: A question of style (finding item in list of tuples)

2012-05-21 Thread Chris Angelico
On Mon, May 21, 2012 at 10:37 PM, Roy Smith wrote: > The above code works, but it occurs to me that I could use the much > shorter: > >    def experience_text(self): >        return dict(CHOICES).get("self.level", "???") > > So, the question is, purely as a matter of readability, which would you >

A question of style (finding item in list of tuples)

2012-05-21 Thread Roy Smith
I've got this code in a django app: CHOICES = [ ('NONE', 'No experience required'), ('SAIL', 'Sailing experience, new to racing'), ('RACE', 'General racing experience'), ('GOOD', 'Experienced racer'), ('ROCK', 'Rock star'), ] def experience_

Re: A question of style .....

2009-07-15 Thread Bearophile
tuxagb: > If I have to write an extension module with many objects, how can I > organizing the code? > I think: every object in a separate file, and a last file with the > PyInit_. function. But is unmenageable . > > Solutions? What do you think about using Cython? Bye, bearophile -- htt

A question of style .....

2009-07-15 Thread tuxagb
If I have to write an extension module with many objects, how can I organizing the code? I think: every object in a separate file, and a last file with the PyInit_. function. But is unmenageable . Solutions? Thanks! -- http://mail.python.org/mailman/listinfo/python-list