[python-win32] error in list length
Larry Bates
larry.bates at websafe.com
Thu Jul 10 18:13:02 CEST 2008
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 at 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
More information about the python-win32
mailing list