Package pysys :: Package utils :: Module filereplace
[hide private]
[frames] | no frames]

Module filereplace

source code

Functions [hide private]
 
replace(input, output, dict={}, marker='')
Read an input file, and write to output tailoring the file to replace set keywords with values.
source code
Variables [hide private]
  __package__ = 'pysys.utils'
Function Details [hide private]

replace(input, output, dict={}, marker='')

source code 

Read an input file, and write to output tailoring the file to replace set keywords with values.

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)
Raises: