Python newbie question re Strings and integers

rmac rmacneill at gmail.com
Fri Sep 19 01:10:02 CEST 2008



the following code attempts to extract a symbol name from a string:
    extensionStart = int(filename.rfind('.'))
    filenameStart = int(filename.rfind('/'))
    #print 'Extension Start - ' + str(extensionStart)
    #print 'FileName Start - ' + str(filenameStart)
    currentSymbol=filename[int(filenameStart),int(extensionStart)]

Uncommenting the print statements clearly show the values to be
integers (and without the str casts actually provide int+string
errors)

However, executing this code results in...
    opening - /Users/rmac/Documents/Sandbox/data/MarketData/AA.csv
    Traceback (most recent call last):
      File "rHistFileToDB_Equities.py", line 25, in <module>
        currentSymbol=filename[int(filenameStart),int(extensionStart)]
    TypeError: string indices must be integers

Running Python 2.5.2_5 on OSX



More information about the Python-list mailing list