pysys.utils.filereplace¶
Replacing tokens in a text file.
replace¶
- pysys.utils.filereplace.replace(input, output, dict={}, marker='', encoding=None)[source]¶
Read an input file, and write to output tailoring the file to replace set keywords with values.
- Deprecated
It is recommended to use
pysys.basetest.BaseTest.copy()
instead of this method.
The replace method reads in the contents of the input file line by line, checks for matches in each line to the keys in the dictionary dict parameter, and replaces each match with the value of the dictionary for that key, writing the line to the output file. The marker parameter is a character which can be used to denoted keywords in the file to be replaced. For instance, with dict of the form
{'CATSEAT':'mat', 'DOGSEAT':'hat'
}, marker set to ‘$’, and an input file:The cat sat on the $CATSEAT$ The dog sat on the $DOGSEAT$
the ouptut file produced would have the contents:
The cat sat on the mat The dog sat on the hat
- Parameters
input – The full path to the input file
output – The full path to the output file with the keywords replaced
dict – A dictionary of key/value pairs to use in the replacement
marker – The character used to mark key words to be replaced (may be the empty string if no characters are used)
encoding – Specifies the encoding to be used for opening the file, or None for default.
- Raises
FileNotFoundException – Raised if the input file does not exist