Maintaining leading zeros with the lstrip string function?

Steve Holden steve at holdenweb.com
Mon Jul 23 20:37:28 EDT 2007


Randy Kreuziger wrote:
> Thanks for the basename suggestion.  That almost works.  I'm running 
> into a problem with some of the directory names when they include 
> \800x\   see below.
> �-----------------------------------------------------------------------------
> import sys, os, string
> 
> teststring = 'C:\shoreline\dvd\prep area\800x\060623_00001.jpg'
> print  os.path.basename(teststring)
> �-----------------------------------------------------------------------------
> Results in
> 800x0623_00001.jpg
>  
> But it needs to be
> 060623_00001.jpg
> 
You need to be careful with those backslashes!

 >>> teststring = 'C:\shoreline\dvd\prep area\800x\060623_00001.jpg'
 >>> teststring
'C:\\shoreline\\dvd\\prep area\\800x0623_00001.jpg'
 >>> teststring = r'C:\shoreline\dvd\prep area\800x\060623_00001.jpg'
 >>> teststring
'C:\\shoreline\\dvd\\prep area\\800x\\060623_00001.jpg'
 >>>

regards
  Steve
-- 
Steve Holden        +1 571 484 6266   +1 800 494 3119
Holden Web LLC/Ltd           http://www.holdenweb.com
Skype: holdenweb      http://del.icio.us/steve.holden
--------------- Asciimercial ------------------
Get on the web: Blog, lens and tag the Internet
Many services currently offer free registration
----------- Thank You for Reading -------------




More information about the Python-list mailing list