A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from http://mail.python.org/pipermail/python-list/2001-April/069334.html below:

writing to locals (was RE: execfile: NameError exception thrown for things in locals())

writing to locals (was RE: execfile: NameError exception thrown for things in locals()) writing to locals (was RE: execfile: NameError exception thrown for things in locals())Fredrik Lundh fredrik at pythonware.com
Mon Apr 9 16:13:14 EDT 2001
James_Althoff at i2.com wrote:
> ... my class ...
>
>     def setFormula(self,formulaString):
>      self.formula = formulaString
>
>     def getCalculatedValueAt(self,rowIndex):
>         count = self.getColumnCount()  # excludes the calculated column
>         localsDict = locals()
>         for columnIndex in xrange(count):
>             columnID = 'c' + str(columnIndex+1)
>             columnValue = self.getValueAt(rowIndex,columnIndex)
>             localsDict[columnID] = columnValue
>         try:
>             value = eval(self.formula)
>         except:
>             value = 'Invalid formula'
>         return value

         localsDict = {}
         for columnIndex in xrange(count):
             columnID = 'c' + str(columnIndex+1)
             columnValue = self.getValueAt(rowIndex,columnIndex)
             localsDict[columnID] = columnValue
         try:
             value = eval(self.formula, localsDict)
         except:
             value = 'Invalid formula'
         return value

Cheers /F

<!-- (the eff-bot guide to) the standard python library:
http://www.pythonware.com/people/fredrik/librarybook.htm
-->





More information about the Python-list mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4