w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
Python Pass multiple variables through command to change multiple lines in a text file with regex

I replaced the for loop with the following code and it worked:

with open('test1.txt') as f:
    line1 = f.readline()
    line2 = f.readline()
    line3 = f.readline()
    build = re.sub ('build='r'.*','build='+buildpath,line1)
    apps = re.sub ('apps='r'.*','apps='+appspath,line2)
    logs = re.sub ('logs='r'.*','logs='+logspath,line3)
    tf.write(build + apps + logs)

© Copyright 2018 w3hello.com Publishing Limited. All rights reserved.