I read list with 2 columns firstname and surname from csv file
csv_reader_object = csv.reader(path, delimiter=';')
for row in csv_reader_object:
I want to put the name into a contructor but alway get {'Garfield'} instead of Garfield as string
This one is fine:
print(f'Name: {", ".join(row)}')
These are not:
print(str({row[1]}))
print({row[1]})
How to get simple formatted string out of that list?
CodePudding user response:
You are extracting row[1]
and then put it into set (thus {
and }
you see) simply do not that, i.e. replace
print(str({row[1]}))
print({row[1]})
using
print(str(row[1]))
print(row[1])
CodePudding user response:
This is because when you place curly brackets around a string you are actually making a set of single element and when set is printed it is printed with those curly brackets as in
>>> str({"hello"})
"{'hello'}"
>>>
you can fix this by removing those curly brackets as in
print(str(row[1]))
print(row[1])