O'Reilly logo

Python Programming On Win32 by Mark Hammond, Andy Robinson

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Keyword Arguments

Both Python and Excel support keyword arguments. These are generally used when you have a long list of possible arguments to a function, most of which have default values. Excel takes this to extremes; for example, the function to save a workbook is:

WorkBook.SaveAs(Filename, FileFormat, Password, WriteResPassword, ReadOnlyRecommended, 
CreateBackup, AddToMru, TextCodePage, TextVisualLayout)

And that’s a short one: some of the formatting commands have literally dozens of arguments. To call these, you supply only the arguments you want, as follows:

>>> xlBook.SaveAs(Filename='C:\\temp\\mysheet.xls')
>>>

The capitalization of the keywords must be exactly right. Microsoft generally uses mixed case for everything but Filename, but you’ll undoubtedly have a fun time discovering more exceptions.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required