I want to execute code read from an Excel workbook. For some reason the following code does not actually evaluate, however.
import win32com.client
import os
excel = win32com.client.DispatchEx('Excel.Application')
local_dir = os.getcwd()
book = excel.Workbooks.Open(local_dir+'\\Condition.xlsx', True)
sheet = book.Sheets('Sheet1')
condition = sheet.Cells(1,3).Value
print condition
print eval(condition)
excel.Workbooks.Close()
If the cell in question contains "1+2", the above code just prints out "1+2", not "3". If I replace "condition" with "1+2", it evaluates correctly. Any idea why this isn't working?