Text Manipulation in Python

William Park parkw at better.net
Wed Nov 10 06:31:34 EST 1999


On Wed, Nov 10, 1999 at 08:46:42AM +0000, Edward Hasted wrote:
> I am completely new to Python.
> 
> We want to use it to alter specific lines in template files, typically 
> something like changing:-
> 
> Variable = 1234
> 
> to 
> 
> Variable = Company Name
> 
> The text manipulation strings within Python seem to work sequentially 
> rather than on a line basis.
> 
> 1. Is this correct?

Well, you have read line by line.  Try something like
    f = open(..., "r")
    for s in f.readlines():
	s = ...do string substitution using 're' or 'string' module...
	print s
But, if you're running Unix, you can also use 'sed'.

> 2. What is the best way to do text searching and manipulation within 
> Python.
> 
> Many thanks,
> 
> Edward 
> 
> 
> -- 
> http://www.python.org/mailman/listinfo/python-list




More information about the Python-list mailing list