On Sep 27, 6:23 pm, Alessandro <alexxx.ma...@gmail.com> wrote: > > I have a string defining a path, were all the spaces have been > converted to underscores. > (...) > > notice that the real path can contain BOTH spaces and underscores. > > How can I feed it to os.path.exists() ???
You are losing some information, there is no other choice to test all the combinations. Something like this should do the trick (/!\ quick and dirty solution /!\) def testpath(path): tmp=path.split("_") for i in range(2**(len(tmp)-1)): res="" for j in range(len(tmp)): if j>0: if (i & 2**(j-1))==0: res += " " else: res += "_" res+=tmp[j] if os.path.exists(res): return True return False Raphael -- http://mail.python.org/mailman/listinfo/python-list