One drawback to the use of a Python list
for source files is that
each file name must be enclosed in quotes
(either single quotes or double quotes).
This can get cumbersome and difficult to read
when the list of file names is long.
Fortunately, SCons and Python provide a number of ways
to make sure that
SConstruct file stays easy to read.
To make long lists of file names
easier to deal with, SCons provides a
that takes a quoted list of file names,
with the names separated by spaces or other white-space characters,
and turns it into a list of separate file names.
Split function turns the
previous example into:
Program('program', Split('main.c file1.c file2.c'))
(If you're already familiar with Python,
you'll have realized that this is similar to the
in the Python standard
split() member function of strings,
does not require a string as input
and will wrap up a single non-string object in a list,
or return its argument untouched if it's already a list.
This comes in handy as a way to make sure
arbitrary values can be passed to SCons functions
without having to check the type of the variable by hand.)
Putting the call to the
can also be a little unwieldy.
A more readable alternative is to
assign the output from the
to a variable name,
and then use the variable when calling the
src_files = Split('main.c file1.c file2.c') Program('program', src_files)
doesn't care how much white space separates
the file names in the quoted string.
This allows you to create lists of file
names that span multiple lines,
which often makes for easier editing:
src_files = Split("""main.c file1.c file2.c""") Program('program', src_files)
(Note in this example that we used the Python "triple-quote" syntax, which allows a string to contain multiple lines. The three quotes can be either single or double quotes.)