Question: So basically I have a file with 3 lines and each line has 3 numbers

```
7,2,1
10,0,0
2,8,0 

```

Then depending on the user input I want to +1 to one of the numbers on the line.

```
if user_input == 1
     +1 to line1Number1
elif user_input == 2 
     +1 to line1Number2
elif user_input == 3
     +1 to line1Number3
else 
    print"error"

```

Answer: 
You can do something like this:

```
In [1634]: user_input = int(input()) 

In [1627]: with open('t.txt', 'r') as f: 
      ...:     lines = f.readlines() 

      ...: for c,l in enumerate(lines): 
      ...:     if c == user_input: 
      ...:         lst = l.split(',') 
      ...:         lst = [int(x) + 1 for x in lst] 
      ...:         print(lst)

[3, 9, 1]

```
Another way of doing this (explanation in comment). Reads from in.txt, write to out.txt.

```
# ask user input for which column to update
update_column = int(input("Column to update 1,2 or 3?"))
# open file to read from
with open("in.txt", "r") as f:
    # for every line in the text file
    for line in f.readlines():
        # make the numbers into an integer list (remove new line, split by comma, and convert to int)
        new_line = list(map(int, line.strip().split(",")))
        # add one to the number in the column input 
        new_line[update_column -1] +=1
        # open a file for a pending
        with open("out.txt", "a") as of:
            # append the list removing brackets and adding a new line
            of.write(str(new_line).replace("[","").replace("]","") + "\n")

```