check path.exists() with a "converted" path

Raphaël Plasson rplasson at
Mon Sep 27 11:46:08 CEST 2010

On Sep 27, 6:23 pm, Alessandro < at> 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):
    for i in range(2**(len(tmp)-1)):
        for j in range(len(tmp)):
            if j>0:
                if (i & 2**(j-1))==0:
                    res += " "
                    res += "_"
        if os.path.exists(res):
            return True
    return False


More information about the Python-list mailing list