@JonB said:

data=read(f)

Shouldn't it be f.read()?

I have to find all the numerical values in that text file and compute their sum. How can I do this in Pythonista?

Assuming each line has exactly one numerical value:

def read_ints_from_file(filepath): """ Read integers from file path filepath. """ values = [] # open file read-only with open(filepath, "r") as fin: # read file line by line for line in fin: # remove any leading/trailing whitespace characters and convert to integer v = int(line.strip()) values.append(v) return values # example usage. sum() calculates the sum of the argument(s) print(sum(read_ints_from_file("path/to/textfile.txt")))

If the file contains text other than the numbers, you should look into regular expressions (using re) to find the values.