Reputation: 702
I have to variables one="{}{}{}T{}:{}:{}" and two='2021,-10,-28,05,40,33'
When i try to use print(one.format(two)) i am getting errors. IndexError: Replacement index 1 out of range for positional args tuple.
guessing it is because the two variable is being seen as a string.
So I switched and tried to do the *args
method.
for item in two:
item = str(item)
data[item] = ''
result = template.format(*data)
However if I switch two='2021,-10,-28,00,00,00.478'
it fails because a dictionary is unique. so how do i get the first method to work or is there a better solution.
Upvotes: 0
Views: 399
Reputation: 7627
You should split the two
into list and then unpack it with *
one="{}{}{}T{}:{}:{}"
two='2021,-10,-28,05,40,33'
print(one.format(*two.split(','))) # 2021-10-28T05:40:33
Upvotes: 3