Using a Node's File Name as a String

SCons User Guide 0.98.0
Prev | Chapter 5. Node Objects | Next

# 5.4. 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
          hello does not exist!
          cc -o hello.o -c hello.c
          cc -o hello hello.o

Prev | Home | Next
Printing `Node` File Names | Up | Dependencies