Before I post an answer let me take the time to explain what you're doing wrong so you don't repeat the same bad habits.
This line could be written better:
wtr = csv.writer(open ('test.csv', 'w'), delimiter=';', lineterminator='\n')
In Python it can be written as:
with open('items.csv', 'w', newline='') as csvfile:
In your code sample, you never used with. It's a good time to read about why you should use it.
Under that you can specify how and what to write, like this:
item_writer = csv.writer(csvfile, delimiter=', quoting=csv.QUOTE_MINIMAL)
This for loop could be written better:
for label in testarray:
testarray.write([label])
You don't need to surround the label variable with [] brackets because it's not a list. You are referencing items from the list.
It can be written like this:
for item in testarray:
item_writer.writerow(item)
This may not be what you want, because it will write every item in the list on it's own line.
Putting everything together, we get:
import csv
def main():
testarray = ["Hello", "My", "Name", "is", "John"]
with open('test.csv', mode='w') as employee_file:
employee_writer = csv.writer(employee_file, delimiter=',', quotechar='"',
quoting=csv.QUOTE_MINIMAL)
employee_writer.writerow(testarray)
print("done")
# Will output:
# Hello,My,Name,is,John
if __name__ == '__main__':
main()
csvfile.csvdocumentation". There is an example there doing exctly that. The OP is having some trouble with it, but has not taken time to find out what it is that they want to ask.