Jersey Fonseca
Jersey Fonseca

Reputation: 9

Variable not printing in python

I have an array of strings that I am trying to iterate through and store the string into another string. When I write this to another file, though, it comes out as %s.

Here is a snippet of the code:

for labels in rows[0]:
    if (labels == 'Year'):
        continue
    else:
        dataset = """{{\nlabel: '%s',\ndata: '%s',\nbackgroundColor: 'rgba(168, 191, 18, 0.7)',\nborderColor: 'rgba(168, 191, 18, 1)',\nborderWidth: 0\n}},\n""" % labels, labels
        f.write(dataset)
f.close()

Also, I was not sure how to split the dataset line into multiple lines while still keeping the formatting that it should. Can someone please help? Thank you!

Upvotes: 0

Views: 104

Answers (1)

SampleText2k77
SampleText2k77

Reputation: 198

Tried your code. It prints not enough arguments for format string. Try % (labels, labels)

Upvotes: 1

Related Questions