Re: [Tutor] replacing a long list of if,elif

2009-10-23 Thread Kent Johnson
On Fri, Oct 23, 2009 at 11:05 AM, John wrote: >  mydict = {'int': 'I', 'char':'C', 'bool':'B'} >  for fldType in fieldList: >    try: >        fld = mydict[fldType] >    except: >        fld = '?' Use fld = mydict.get(fldType, '?') > I also considered some sort of  lambda function as > >

Re: [Tutor] replacing a long list of if,elif

2009-10-23 Thread Emile van Sebille
myDict.get(fldType, None) this will output the value from myDict if the key exists, if not it will return None Thanks this looks perfect - did not know dict.get() You may also want to consider {}.setdefault -- that would collect the fldType entries not defined. >>> a = {'a':1,'b':2} >>

Re: [Tutor] replacing a long list of if,elif

2009-10-23 Thread John
On Friday 23 October 2009 08:05:29 am John wrote: > I'm using python 2.5 > > I have a long list of if, elif, else. I always thought it was very NOT > pythonic. It's easy to read but not pretty. > > for fldType in fieldList: > if "int" in fldType: > fld = "I" > elif "char" in fldType : >

Re: [Tutor] replacing a long list of if,elif

2009-10-23 Thread vince spicer
On Fri, Oct 23, 2009 at 9:05 AM, John wrote: > I'm using python 2.5 > > I have a long list of if, elif, else. I always thought it was very NOT > pythonic. It's easy to read but not pretty. > > for fldType in fieldList: > if "int" in fldType: > fld = "I" > elif "char" in fldType : >

[Tutor] replacing a long list of if,elif

2009-10-23 Thread John
I'm using python 2.5 I have a long list of if, elif, else. I always thought it was very NOT pythonic. It's easy to read but not pretty. for fldType in fieldList: if "int" in fldType: fld = "I" elif "char" in fldType : fld = "C" elif "bool" in fldType : fld = "B" .

Re: [Tutor] Help with my program

2009-10-23 Thread Kent Johnson
On Thu, Oct 22, 2009 at 11:59 PM, Kenny Shen wrote: > Hi tanner, > > I suppose the following is possible: > > class A: >   def __init__(self): >   self.height = 1 >   self.weight = 7 >   self.name = "tanner" >   self.grade = "A" >   def getinfo(self): >   info = [] >   info

[Tutor] Help with my program

2009-10-23 Thread tanner barnes
Ok so im in need of some help! I have a program with 2 classes and in one 4 variables are created (their name, height, weight, and grade). What im trying to make happen is to get the variables from the first class and use them in the second class.

Re: [Tutor] i can't for the life of me get "#! /usr/bin/env python" or "#!/usr/bin/python" to work

2009-10-23 Thread Stuart Sears
On 21/10/09 23:12, Luke Paireepinart wrote: > On Wed, Oct 21, 2009 at 4:56 PM, Jason Willis > wrote: > >> so i changed the .bashrc and added at the end : >> PATH="/home/compy/pythons:$PATH" ###which is the actual path to my >> python proggies### That should work, but you'll have to tell the she