Python - replace a line by its column in file
Question: Sorry for posting such an easy question, but i couldn't find an answer on
google. I wish my code to do something like this code:

    
    
    lines = open("Bal.txt").write
    lines[1] = new_value
    lines.close()
    

p.s i wish to replace the line in a file with a value


Answer: xxx.dat before:

    
    
    ddddddddddddddddd
    EEEEEEEEEEEEEEEEE
    fffffffffffffffff
    
    with open('xxx.txt','r') as f:
        x=f.readlines()
    x[1] = "QQQQQQQQQQQQQQQQQQQ\n"
    with open('xxx.txt','w') as f:
        f.writelines(x)
    

xxx.dat after:

    
    
    ddddddddddddddddd
    QQQQQQQQQQQQQQQQQQQ
    fffffffffffffffff
    

Note:f.read() returns a string, whereas f.readlines() returns a list, enabling
you to replace an occurrence within that list.  
Inclusion of the `\n` (Linux) newline character is important to separate
line[1] from line[2] when you next read the file, or you would end up with:

    
    
    ddddddddddddddddd
    QQQQQQQQQQQQQQQQQQQfffffffffffffffff
    

