xlwt: 'CommonToken' object has no attribute 'txt'

I have written a script for generating reports in Excel using xlwt. It usually works just fine but every now and then I get this error:

Traceback (most recent call last):
  File "...\report.py", line 339, in <module>
    pa.write_row([Formula('{0} - {1}'.format(my_data[i], rowcol_to_cell(marker_top, i+2))) for i in xrange(rng)], 2, rownum1-rownum2, style=pa_data2)
  File "C:\Python27\lib\site-packages\xlwt\ExcelFormula.py", line 17, in __init__
    self.__parser.formula()
  File "C:\Python27\lib\site-packages\xlwt\ExcelFormulaParser.py", line 87, in formula
    self.expr("V")
  File "C:\Python27\lib\site-packages\xlwt\ExcelFormulaParser.py", line 94, in expr
    self.prec0_expr(arg_type)
  File "C:\Python27\lib\site-packages\xlwt\ExcelFormulaParser.py", line 139, in prec0_expr
    self.prec1_expr(arg_type)
  File "C:\Python27\lib\site-packages\xlwt\ExcelFormulaParser.py", line 157, in prec1_expr
    self.prec2_expr(arg_type)
  File "C:\Python27\lib\site-packages\xlwt\ExcelFormulaParser.py", line 187, in prec2_expr
    self.prec3_expr(arg_type)
  File "C:\Python27\lib\site-packages\xlwt\ExcelFormulaParser.py", line 216, in prec3_expr
    self.prec4_expr(arg_type)
  File "C:\Python27\lib\site-packages\xlwt\ExcelFormulaParser.py", line 234, in prec4_expr
    self.prec5_expr(arg_type)
  File "C:\Python27\lib\site-packages\xlwt\ExcelFormulaParser.py", line 257, in prec5_expr
    self.primary(arg_type)
  File "C:\Python27\lib\site-packages\xlwt\ExcelFormulaParser.py", line 492, in primary
    raise Exception("[formula] found unexpected NAME token (%r)" % name_tok.txt)

AttributeError: 'CommonToken' object has no attribute 'txt'

pa is an instance of a class I made for convenience whose methods are simply shortcuts for common xlwt actions. rowcol_to_cell is xlwt.Utils.rowcol_to_cell.

In this case, the formula being written is in the form float - cell reference, and my_data is a pandas.Series().

As I said above, 99% of the time this works just fine, but when it decides not to work only restarting my computer seems to fix it (which is really annoying!). Can anybody shed some light on this? Thank you.

EDIT:

Just restarted my computer and I'm still having this issue. Which means that I have no idea how I fixed this in the past.

Answers


I got a similar error when trying to add a VLOOKUP formula. It turned to be an error in the formula i was trying to add. I figured out the formula error by trying it manually in an excel sheet. After fixing the forumula the xlwt error went away.


Need Your Help

Best method for Flex to PHP communication?

php xml flex amfphp weborb

What is the best method for communication between Flex and PHP?

beforeSend jquery ajax

jquery ajax authentication

I am making a simple login for my website and I am using ajax to interact with database. I wanted to make it a bit safe so I search for security for ajax so I search for AJAX authentication and rea...