value exists (newbie question)

George Sakkis george.sakkis at gmail.com
Tue Sep 19 15:31:40 EDT 2006


eldorado wrote:

> Hello,
>
> I am trying to parse some files so that if a postal code exists, but is
> longer than five digits it will return me only the first five digits:
> ...
> for insDict in insureDict:
>  	insDict['postalcode'] = insDict.get('postalcode')[:5]
> ...
> This works, except for when I get a blank postalcode.  In which case I get
> the following error.
> ERR exceptions.TypeError: iteration over non-sequence
>
> What I would like to do is to check to make sure a value exists.  I just
> cannot seem to find the syntax to do that.  (not asking anyone to write my
> code, just looking for a pointer)
>
> Thanks

Hint: dict.get() takes an optional second argument.

George

PS: To make a new thread, don't hit "reply" on an existing thread and
change the subject. Just make a new thread.. duh.




More information about the Python-list mailing list