I get this error when calling my python script from command line, passing in an input string (parameter 1) and a blank string (parameter 2) that will store my output from parsing this input string in my module
C:\Windows\system32>set project_name=
C:\Windows\system32>echo "%project_name%" " "
C:\Windows\system32>"C:\Python27\python" "C:\IR125422\GetProject1.py" "#p=/Product Delivery/Product Delivery.pj#s=Team P rojects/Team Projects.pj#s=Platform Pack/Platform Pack.pj#s=Runtime/Runtime.pj" project_name
Traceback (most recent call last): File "C:\IR125422\GetProject1.py", line 5, in <module>
startpos = rindex("/",stext) NameError: name 'rindex' is not defined
My python program takes the string staring with "#p" and locates the last substring "/" in the string, then copies into the string project_name the remainder of this string from the last "/" to the end of the string. So after the program is run project_mane should contain "runtime.pj"
Here is the program
import os, sys
stext = sys.argv[1]
rtext = sys.argv[2]
startpos = rindex("/",stext)
rtext = stext(startpos+1,len(rtext))
print "Extracting project"
print rtext;
However it seems that the string method rindex is not recognised. Do I need to add a module to my "Import" section? I thought that this was not required for string handling in python as it is intrinsic to python