string % dictionary question
Bryan
belred1 at yahoo.com
Tue Sep 14 00:47:56 EDT 2004
More information about the Python-list mailing list
Tue Sep 14 00:47:56 EDT 2004
- Previous message (by thread): string % dictionary question
- Next message (by thread): string % dictionary question
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Sam Sungshik Kong wrote:
> Thanks for the reply.
>
> What if the string is more complicated?
> For example,
>
> di = {}
> di["name"] = "Sam"
> di["age"] = None
> s = "name: %(name)s, age: %(age)d" % di
>
> Thanks.
>
> Sam
>
instead of setting di['age'] to None, set it to empty string. if you are setting di['age'] with a variable then you can
insure that you use an empty string for None by doing something like this:
di['age'] = somevar or ''
bryan
- Previous message (by thread): string % dictionary question
- Next message (by thread): string % dictionary question
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list