Maintaining leading zeros with the lstrip string function?

Randy Kreuziger KREUZRSK at DFW.WA.GOV
Mon Jul 23 14:41:27 EDT 2007


I need just the file name from a string containing the path to a file.  The name of the file starts with zeros.  This is problematic because the  lstrip function strips them leaving this as the result:
6128.jpg
 
 
How do I strip the path without losing the leading zeros in the file name?
 
―---------------------------------------------
import sys, os, win32com.client, string

teststring = 'C:\shoreline\dvd\prep area\800x\\006128.jpg'
print string.lstrip(teststring, 'C:\shoreline\dvd\prep area\800x\\')

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20070723/11eb139c/attachment.html>


More information about the Python-list mailing list