Using a Node's File Name as a String
Printing a Node's name
as described in the previous section
works because the string representation of a Node
is the name of the file.
If you want to do something other than
print the name of the file,
you can fetch it by using the builtin Python
str function.
For example, if you want to use the Python
os.path.exists
to figure out whether a file
exists while the SConstruct file
is being read and executed,
you can fetch the string as follows:
import os.path
program_list = Program('hello.c')
program_name = str(program_list[0])
if not os.path.exists(program_name)
print program_name, "does not exist!"
|
Which executes as follows on a POSIX system:
% scons -Q
The object file is: hello.o
The program file is: hello
cc -c -o hello.o hello.c
cc -o hello hello.o
|