I’m trying to make a string by inserting a tuple. I’m trying to get 'k = as.numeric(list(1, 2, 3))' as my output:
j = (1, 2, 3)
'k = as.numeric(list%r)' % j
This returns
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: not all arguments converted during string formatting
Could someone please explain what went wrong here? Thanks.
If you give
%a tuple, it assumes you want to use the elements of the tuple as the items to format, even if the format string contains only one placeholder. The solution is to wrap the tuple in a one-tuple: