Scripting 5.7. Including other scripts

You can include other scripts within your script:

a = 5
include square.praat
writeInfoLine: a

The Info window will show the result 25 if the file square.praat contains the following:

a = a * a

The inclusion is done before any other part of the script is considered, so you can use the form statement and all variables in it. Usually, however, you will put some procedure definitions in the include file, that is what it seems to be most useful for. Watch out, however, for using variable names in the include file: the example above shows that there is no such thing as a separate name space.

Note that you do not put quotes around the name of the include file. This is because the name of the include file has to be given explicitly; you cannot put it into a variable, for instance.

You can use full or relative file names. For instance, the file square.praat is expected to be in the same directory as the script that says include square.praat. If you use the ScriptEditor, you will first have to save the script that you are editing before any relative file names become meaningful (this is the same as with other uses of relative file names in scripts).

You can "nest" include files, i.e., included scripts can include other scripts. However, relative file names are always evaluated relative to the directory of the outermost script.

The include statement can only be at the start of a line: you cannot put any spaces in front of it.

Links to this page


© ppgb, January 11, 2014