Hi, Thank you for your reply. I will remember your point and send the code from the console.
BRgds, kNish Larry Bates wrote: > > kNish wrote: >> Hi, >> >> The following lines of code gives an error starting with >> line where len() is used >> >> >> local_BkFiles = glob.glob(localDirectoryName+'\\*' + >> data + '*bk*') >> local_BkFiles.sort(key=str.upper) >> last_pv_File_Name = local_PvFiles[len(local_PvFiles)-1] >> split_last_pv_File_Name = >> re.search(data+"_bk[0-9]{2}_[a-z]{3}_pv[0-9]{2}",last_pv_File_Name ) >> lastPv_FileVersion = >> re.search('(?<=pv)\d+',split_last_pv_File_Name.group(0)) >> >> >> This code is being called in a procedure or function def. How may I >> solve this. >> >> >> BRgds, >> >> >> kNish >> >> >> ------------------------------------------------------------------------ >> >> _______________________________________________ >> python-win32 mailing list >> python-win32@python.org >> http://mail.python.org/mailman/listinfo/python-win32 > > Since you didn't post your full traceback (you should always do that in > the > future), we are guessing: > > local_PvFiles isn't defined prior to trying to determine its length. > > The way to get the last element of a list is: > > local_PvFiles[-1] > > you don't need to do all the length gymnastics. > > I'm no regex expert, so I'll leave that part to someone else but if the > filenames are a fixed format, you don't need regex at all to extract the > version. If it is a completely variable format, then you would. > > -Larry > > > _______________________________________________ > python-win32 mailing list > python-win32@python.org > http://mail.python.org/mailman/listinfo/python-win32 > > -- View this message in context: http://www.nabble.com/error-in-list-length-tp18376387p18562507.html Sent from the Python - python-win32 mailing list archive at Nabble.com. _______________________________________________ python-win32 mailing list python-win32@python.org http://mail.python.org/mailman/listinfo/python-win32