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

Chris Rebert clp2 at
Mon Sep 27 11:35:24 CEST 2010

On Mon, Sep 27, 2010 at 2:23 AM, Alessandro <alexxx.magni at> wrote:
> Hi, I'm a python newbie with a problem too hard to tackle.
> I have a string defining a path, were all the spaces have been
> converted to underscores.
> How can I find if it corresponds to a real path?
> e.g. a string like '/some/path_to/directory_1/and_to/directory_2'
> with a real path: '/some/path_to/directory 1/and_to/directory 2'
> notice that the real path can contain BOTH spaces and underscores.
> How can I feed it to os.path.exists() ???

Use the `glob` module instead:

from glob import glob
real_paths = glob(underscored_path.replace('_','[_ ]'))
#note: it's possible for there to be multiple matches


More information about the Python-list mailing list