I created a csv function that should ask for a file path and for X number of strings to write to the file with an specified csv delimiter.
def WRITE_csv(csv_path,*args):
with open(csv_path, "ab") as f:
csv_list=csv.writer(f,delimiter='|')
csv_string=""
for arg in args:
csv_string=csv_string+","+arg
csv_string=csv_string[1:]
csv_list.writerow([csv_string])
The problem is that the csv module is writing , instead of |
As a bonnus, I wanted to replace:
csv_string=""
for arg in args:
csv_string=csv_string+","+arg
With a one-line function
csv_string="".format(','.join(arg for arg in args))
but it always giving me an empty string!
delimiterargument lets you specify your own delimiter. Provided you actually use more than one column...argsinto a single string with commas? You appear to misunderstand how the writer works, you pass in a sequence of columns, not one string.csv_list.writerow([string1,string2,string3,ect..]),commas are not string values, they are Python syntax to delimit the different elements that you are asking Python to put into the list.