Trying to add a row to my CSV file in the format; \"name, value\". Here is the CSV file:
Japanese Yen,169.948
US Dollar,1.67
Pound Sterling,1
Euro,5.5
Well, do some testing before asking. Before file.write(adding)
you could have put a print(adding)
of print(adding.__repr__())
to see what is Pythons problem with your adding
instance. You would have seen it is like ('Euro', '5.5')
which is a tuple. True if Python complains it needs a string instead of a tuple you passed there a tuple. First, don't convert to float the newRt
input since you need it as a string either. What you need here is adding = ','.join((addCurrency, newRt)) + '\n'
or adding = '{},{}\n'.format(addCurrency, newRt)
or adding = addCurrency + ',' + newRt + '\n'
. Try to figure out simple problems like this one before questioning SO. Read the tutorial of the documentation.