pytuflow.ECF.insert_input#
- ECF.insert_input(ref_inp, input_text, after=False, gap=0)#
Inserts an input before, or after, another reference input.
- Parameters:
ref_inp (InputBuildState) – The input to place the new command before, or after.
input_text (str) –
The input text to add to the control file (i.e. the TUFLOW command). Leading whitespace will be respected. However, the input will be indented automatically depending on its scope and generally is not required to be considered by the user in the input text.
Alternatively, an existing input instance can be passed in. If the input does not already exist in the control file, the input instance will be added directly. If the input already exists within the control file, a copy of the input will be made and added.
after (bool, optional) – If True, the new input will be inserted after the referenced input, if set to False, the new input will be inserted before. Default is False.
gap (int, optional) – The number of blank lines to add before, or after (depending on the
after
parameter), the new input. This has no impact on the TUFLOW model, but can be useful for readability of the control file when it is written to disk. Default is 0.
- Returns:
The input that was added. The input type will be determined by the
input_text
string e.g. if the text isRead GIS Z Shape == ...
, then the return input will be of typeGisInput
.- Return type:
InputBuildState
Examples
1! Control File 2Hardware == GPU 3SGS == On
The following code inserts a new input to the top of the control file, before the first input:
>>> cf = ... # assume this is the loaded control file object >>> inp = cf.inputs[0] >>> new_inp = cf.insert_input(inp, 'Solution Scheme == HPC') >>> ref_inp <SettingInput> Solution Scheme == HPC
The content of the control file can be previewed using
preview()
:>>> cf.preview() Solution Scheme == HPC Hardware == GPU SGS == On
The new input is not written to disk until
write()
is called.undo()
can be used to revert the last change made to the control file, which in this case would remove the new command.