Converting a set of data to string and then into a file

Robert Brewer fumanchu at amor.org
Thu Oct 7 11:43:42 EDT 2004


Thomas Guettler wrote:
> Am Thu, 07 Oct 2004 06:30:58 -0700 schrieb Shufen:
> 
> > Hi,
> >  
> > I have set up a upload form where user can add data into 
> the form via
> > a web browser and submit it. And these data entered by the user will
> > be grabbed by:
> > 
> > xxxx = data.getvalue.('xxxx')     # data is the name of the form
> 
> > The error stated that I can't concatenate 'str'
> > and 'NoneType'.
> 
> Hi,
> 
> You can do it like this:
> 
> foo=data.getvalue("....")
> if foo==None:
>     foo=""

Just to add an idiom I find clean and reasonable... I'd write:

foo = data.getvalue("....") or ""

It might perform an 'extra' instruction if getvalue == "", but I
generally don't care; I find that the compression into one line
summarizes the operation nicely.


Robert Brewer
MIS
Amor Ministries
fumanchu at amor.org



More information about the Python-list mailing list