[Tutor] identifying the calling module/function
tetsuo2k6 at web.de
tetsuo2k6 at web.de
Sat Mar 8 13:57:28 CET 2008
Jeff Younker schrieb:
>
> Telling us your goal might allow us to recommend a better
> and faster way of accomplishing it.
>
> - Jeff Younker - jeff at drinktomi.com -
>
>
>
in dgf.py: (hope the formatting gets good for you, t-bird breaks the
lines badly on my machine...)
def csvwriter(*column_definitions):
"""Edit Me!"""
if sys.argv[0] == /usr/local/bin/xyz.py: # sorry, I am not
allowed to give you guys xyz.py here, or the real name of the script -
my boss is a bit paranoid o.O
output_csv_filename = "xyz.csv"
else:
output_csv_filename = raw_input("Name of the file to produce?
(ATTENTION: WILL BE OVERWRITTEN!) ")
first_row = ";".join(*column_definitions)
try:
file = open(output_csv_filename, "w")
file.write(first_row)
file.close()
except:
print("Couldn't open %s for writing." %
output_csv_filename)
sys.exit(1)
return csv.writer(open(output_csv_filename, "ab"),
delimiter=";", quoting=csv.QUOTE_NONE)
Well, I am starting to realize that the whole thing might be a bit
unnecessary... Just keeps me from creating csv.writer objects everywhere
when the dialect is always the same.
Also, I don't know if I understood the *argument_list thing correctly...
More information about the Tutor
mailing list