[Scons-users] Glob versus glob

Chris BeHanna chris at behanna.org
Fri Sep 7 11:33:31 EDT 2012

On Sep 7, 2012, at 9:10 AM, Peter Steele <pwsteele at gmail.com> wrote:

> I have the statements


> env.VariantDir('obj', 'src', duplicate=0)

> sources = [file.replace("src/", "obj/") for file in glob("src/*.c")+glob("src/fw/*.c")+glob("src/fw/proxy/*.c")]


> that I use to keep my object files separate from my source files. I noticed that there was a Glob scons command so I thought I could use this instead of having to import glob.glob. I change my code to use


> sources = [file.replace("src/", "obj/") for file in Glob("src/*.c")+Glob("src/fw/*.c")+Glob("src/fw/proxy/*.c")]


> because Glob doesn’t return a string some scons class object. I was wondering what would be the most straightforward scons way to use Glob and apply the same string operation to the list that’s returned?

Two ways:

1) In your list comprehension, use file.path or file.abspath.

2) In your list comprehension, use str(file).

Glob() will return nodes for everything that SCons knows how to build, even if it has not yet built it. glob.glob() will not.

Chris BeHanna
chris at behanna.org

More information about the Scons-users mailing list