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
>
>
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}
>>
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 :
>
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 :
>
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" .
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
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.
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