[Tutor] changing two lines in a single python script
bob gailer
bgailer at gmail.com
Wed May 21 19:35:07 CEST 2008
1) When starting a new topic start a new email rather than replying to
another unrelated post.
jatinder Singh wrote:
> Hi .
>
> I am trying to change two lines in a single file (etc/php.ini) but my
> script is not doing this in one time .
What does "in one time" mean?
What IS the script doing?
> Please hav a look
>
> import re
> import sys
> import os
>
> def re_new(pat, rep, s):
> print re.sub(pat, rep, s)
>
It appears that you are using stdout to write the altered file. True?
>
> _stext_1 = 'memory_limit...M' #first word to search
> _rtext_1 = 'memory_limit = 512M ;' #to be replaced with first word
> _stext_2 = 'upload_max_filesize.*M' #Second word
> _rtext_2 = 'upload_max_filesize = 9M ;' #to replace with second
> word
> s = open("/home/ccuser/temp1.txt").readlines()
> for record in s:
> re_new(_stext_1,_rtext_1,record) #if found first then replaceit
> re_new(_stext_2,_rtext_2,record) #else if found second then
> replace that
>
> Will you please help me to correct this script so as to both of the
> changes occure at a singlr time
>
> Thanks for past, now and future
>
> Jatin
--
Bob Gailer
919-636-4239 Chapel Hill, NC
More information about the Tutor
mailing list