views:

47

answers:

1

I wrote a script to automate the process of creating an image gallery. I used os.path.join() for creating paths to new image directories.

I only relized after creating all the galleries that using os.path.join() was not such a good idea as it creates paths with \ (on windows) which causes problems with firefox (it doesn't seem to understand the path format and cant find the images).

Id rather not have to create all the galleries again since the gallery headers have to be entered manually. I thought BeautifulSoups prettify() would fix the paths but it chokes on the backslashes. e.g.

input:

<td><a rel="group" href="images\042.jpg"><img class="gimage" src="images\thumbnails\thumb_042.jpg" alt=""></a></td>

output:

<td>
 <a rel="example_group" href="images">
  <img class="gimage" src="images   humbnails   humb_042.jpg" alt="" />
 </a>
</td>

How can I fix the paths?

+1  A: 

In this case, per the comments, it appears that the problem can be solved with a global substitution of / for \:

import fileinput
import sys
for line in fileinput.input(['test.html'], inplace=True, backup='.bak'):
    sys.stdout.write(line.replace('\\','/'))
unutbu