1

How can you pre-prend a list of names to the example below? I want to call a method many time but the first part will change from ws1, ws2, ws3,...This method is from a module called "xlsxwriter" used to write rows of data inside an excel worksheet.

For example, first loop should create:

ws1.write(1, 0, 'Platform', format)

ws_names = ['ws1', 'ws2', 'ws3']

for entry in ws_names:

    '%s'.write (1, 0, 'Platform', format)  % entry

I am getting this error: AttributeError: 'str' object has no attribute 'write'

I tried, entry.write (1, 0, ... but I get the same error.

Jim Durkin
  • 63
  • 1
  • 1
  • 5
  • why not use `entry.write(1, 0, 'Platform', format)` ? – ZdaR May 29 '15 at 16:23
  • 1
    What is the `ws11 and what is the expected output? – myaut May 29 '15 at 16:23
  • 1
    Your error is telling you that strings don't have a `write()` method, What are you trying to do? – kylieCatt May 29 '15 at 16:23
  • @ IanAuld, @ myaut: the expected output is ws1.write(1,0,'Platform', format) which will write an row in an excel worksheet. This is from a module called: xlxswrite. I have a dozen worksheets or more, and trying to reduce the # of ws[1,2,3,...].write statements. I don't believe this question has been answered -- the referenced link does not help me. – Jim Durkin May 29 '15 at 18:26
  • 1
    @jonrsharpe This isn't a duplicate but it is an XY problem. – jmcnamara May 29 '15 at 22:46
  • 1
    @Jim_Durkin: An easier way to do what you want to do is to use the XlsxWriter `worksheet()` method like this `for worksheet in workbook.worksheets(): worksheet.write(1, 0, 'Platform', format)`. See the docs on [`worksheets()`](https://xlsxwriter.readthedocs.org/workbook.html#workbook-worksheets). – jmcnamara May 29 '15 at 22:48
  • @jmcnamara: This is exactly what I needed. It works. Thank You! – Jim Durkin May 30 '15 at 00:21

0 Answers0