0

I am using Python 2.7. How does you use the index of a loop inside quotation marks? This appears in a option. I have tried putting index in quote() and after % and also format but it is not working.

      for x in range(3,82,7):
          for y in range(10,95,7):
              worksheet.merge_range("A{}".format(x)":A{}".format(y), "", merge_format)

I want the output as

worksheet.merge_range('A3:A10', 'Merged Range', merge_format)
worksheet.merge_range('A10:A17', 'Merged Range', merge_format)

Thanks in advance

  • I'm not sure what you want. Do you want to remove all the non-digit numbers? This may be helpful: https://stackoverflow.com/questions/1450897/python-removing-characters-except-digits-from-string – mattsap Dec 12 '18 at 14:45
  • If you're using the "range" function, the index is just x or y. If you want it to have quotation marks around it, make it `"\"{}\"".format(str(x))` – KuboMD Dec 12 '18 at 14:45

2 Answers2

0

This would be

"A{}:A{}".format(x, y)

Instead of making two format strings and trying to join them, make a single format string that accepts both inputs.

It also looks like you want to iterate through those two loops in parallel, for which you would need to use zip:

for x, y in zip(range(3,82,7), range(10,95,7)):
    worksheet.merge_range("A{}:A{}".format(x, y), 'Merged Range', merge_format)
Patrick Haugh
  • 59,226
  • 13
  • 88
  • 96
0

You put the formats in one place after the quotes.

 "A{}:A{}".format(x, y),
Daniel Roseman
  • 588,541
  • 66
  • 880
  • 895