fetch two values in python from .txt file -


i have .txt file containing values. need fetch 2 values @ time using python , perform operations on , fetch next 2 values.

i want write python script can fetch 2 values @ time. new python.

thanks!

# read file first , split lines in list open('temp.txt', 'r') f:     lines = f.read().splitlines()  # loop through lines, 2 @ time in range(0, len(lines), 2):   # notice last argument '2', makes loop step 2 @ time     val1 = lines[i]     val2 = lines[i+1]     # perform calculation on val1 , val2 

hope helps.


Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -