[Tutor] passing arguments to functions - problem with argument order
tetsuo2k6 at web.de
tetsuo2k6 at web.de
Mon Mar 10 15:18:35 CET 2008
I don't get this - what is the clean way of the order of passing
arguments to functions?
The called function goes like this:
def csvwriter(output_csv_filename=None, *coloumn_definitions):
"""Edit Me!"""
if output_csv_filename == None:
output_csv_filename = raw_input("Name der zu
erzeugenden Datei (vollständiger Pfad)? (ACHTUNG: WIRD ÜBERSCHRIEBEN,
FALLS VORHANDEN!) ")
first_row = ";".join(coloumn_definitions)
print(first_row)
try:
file = open(output_csv_filename, "w")
file.writerow(first_row)
file.close()
except Exception, e:
print("Konnte %s nicht zum Schreiben öffnen.")
sys.exit(e)
return csv.writer(open(output_csv_filename, "ab"),
delimiter=";", quoting=csv.QUOTE_NONE)
The call to the function seems impossible to do. When I say:
writer = dgf.csvwriter(output_csv_filename=None,
"kundennummer", "anrede", "vorname", "nachname", "plz", "ort",
"adresse", "kontoinhaber", "blz", "kto", "bankname", "status",
"spielbeginn", "letzte_aenderung", "importdatum", "briefdatum",
"buchungsdatum", "stornodatum")
I get:
SyntaxError: non-keyword arg after keyword arg
-> So I guess I have to put keyword arg at the end...
When I put output_csv_writer at the end:
writer = dgf.csvwriter("kundennummer", "anrede",
"vorname", "nachname", "plz", "ort", "adresse", "kontoinhaber", "blz",
"kto", "bankname", "status", "spielbeginn", "letzte_aenderung",
"importdatum", "briefdatum", "buchungsdatum", "stornodatum",
output_csv_filename=None)
I get:
TypeError: csvwriter() got multiple values for keyword argument
'output_csv_filename'
-> Am I right that output_csv_filename now becomes "kundennummer" at first?
Also, changing the function definition gives me syntax error:
def csvwriter(*coloumn_definitions, output_csv_filename=None):
^
SyntaxError: invalid syntax
What's going on here? I'm confused...
Paul
More information about the Tutor
mailing list