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: 
```
with open(filename, "r") as txtr:
    data = txtr.readlines()
data = [x.split(",") for x in data]
for i in range(len(data)):
    for j in range(len(data[i])):
        data[i][j] = int(data[i][j])

```

data now has 3 lists with 3 numbers each.

```
if user_input == 1
    data[0] = [x+1 for x in data[0]]

```

just do the same for the rest.

to save to text file:

```
ndata = [",".join(x) for x in data]
nndata = "\n".join(ndata)
with open(filename, "w") as txtw:
    txtw.write(nndata)

```
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")

```