[Tutor] Optional parameter passing

wormwood_3 wormwood_3 at yahoo.com
Mon Jan 12 22:42:42 CET 2009

A small correction to my code, although the point was hopefully still clear:

if options.user: 

From: wormwood_3 <wormwood_3 at yahoo.com>
To: Python Tutorlist <tutor at python.org>
Sent: Monday, January 12, 2009 4:39:30 PM
Subject: [Tutor] Optional parameter passing

Hello all,

I have used *args and **kwargs to have a function accept optional parameters, but is there a lazy way to optionally pass parameters? For example, say my script can accept a number of parameters for a database connection, such as user, password, and database name. The function that makes the MySQL call has a default for user, say "root". So if the user didn't pass in a value for the user option, I don't want to pass it to the function doing the MySQL call. I don't want to have to do:

if options.user: 

and so on for each possible option. Is there a better way?


Samuel Huckins

Homepage - http://samuelhuckins.com
Tech blog - http://dancingpenguinsoflight.com/
Photos - http://www.flickr.com/photos/samuelhuckins/
AIM - samushack | Gtalk - samushack | Skype - shuckins
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20090112/f56848d1/attachment-0001.htm>

More information about the Tutor mailing list