Replace 4-5 lines of a large text file using python
Question: I have a text file in which i need to change

USER PROMPT [Program SIM GENTEST05]

    
    
        <Description />
        <MultiPartMessage>false</MultiPartMessage>
        <NumberOfMultiParts>0</NumberOfMultiParts>
        <Commented>false</Commented>
        <ProgrammingCmdData xsi:type="UserPromptData">
          <Prompt>Program SIM GENTEST05</Prompt>
    

with some customize values. I need some hint to do it in python 2.7


Answer: I would use the [fileinput](https://docs.python.org/2/library/fileinput.html)
library, it would be something like this:

    
    
    import sys
    import fileinput
    
    for i, line in enumerate(fileinput.input('lorem_ipsum.txt', inplace=1)):
        if "<MultiPartMessage>" in line:
            sys.stdout.write(line.replace(
                '<MultiPartMessage>false</MultiPartMessage>', 
                '<MultiPartMessage>something</MultiPartMessage>'))
        elif "<NumberOfMultiParts>" in line:
            sys.stdout.write(line.replace(
                '<NumberOfMultiParts>0</NumberOfMultiParts>', 
                '<NumberOfMultiParts>something</NumberOfMultiParts>'))
        else
            sys.stdout.write(line)
    

