How to replace multiple forward slashes in a directory by a single slash?
Use os.path.abspath
or normpath
to canonicalise the path:
>>> import os.path
>>> os.path.abspath('/home//user////document/test.jpg')
'/home/user/document/test.jpg'
Solution:
This code snippet should solve your issue:
import re
x = '/home//user////document/test.jpg'
re.sub('/+','/', x)
Output:
'/home/user/document/test.jpg'