[Tutor] passing arguments to functions - problem with argument order
Andreas Kostyrka
andreas at kostyrka.org
Mon Mar 10 17:17:28 CET 2008
What you probably want is to pass:
writer(None, "field1", "field2")
Andreas
Am Montag, den 10.03.2008, 16:28 +0100 schrieb tetsuo2k6 at web.de:
> And I thought I might get away without using dicts...
>
> Thanks, Greg
>
>
>
> Greg Graham schrieb:
> > Paul,
> >
> > Python does not allow mixing variable length arguments and keyword arguments in that way. To accomplish what you want, you must add an argument preceded by a "**" which will be a dict containing all of the keyword arguments as key, value pairs. You then have to retrieve the arguments from the dict by name. When called, the keyword arguments must be last.
> >
> > Here is a little example:
> >
> > def test(*column_definitions, **options):
> > print "Column Definitions:" + ", ".join(column_definitions)
> > output_csv_filename = options.get('output_csv_filename', None)
> > print "Output csv filename: " + str(output_csv_filename)
> >
> >
> >>>> test("kundennummer", "anrede", "vorname", "nachname", "plz", "ort", "adresse", "kontoinhaber", "blz", "kto", "bankname", "status", "spielbeginn", "letzte_aenderung", "importdatum", "briefdatum", "buchungsdatum", "stornodatum", output_csv_filename=None)
> > Column Definitions:kundennummer, anrede, vorname, nachname, plz, ort, adresse, kontoinhaber, blz, kto, bankname, status, spielbeginn, letzte_aenderung, importdatum, briefdatum, buchungsdatum, stornodatum
> > Output csv filename: None
> >
> > Greg
> _______________________________________________
> Tutor maillist - Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Dies ist ein digital signierter Nachrichtenteil
Url : http://mail.python.org/pipermail/tutor/attachments/20080310/afe28451/attachment.pgp
More information about the Tutor
mailing list