0

When you have a file with a lot of lines of numbers. I want to know if instead of writing the formula to calculate the numbers for everyline of data. Is there a way to tell it to apply the formula I have made to every line until there are no lines left ,or do I have to re input the formula for everyline so it calculates eachline?

2
Contributors
1
Reply
2
Views
7 Years
Discussion Span
Last Post by Gribouillis
0

Your question is much too vague. You should describe the content of your file and the 'formula' that you want to apply. A general pattern to handle several lines of data is

def handle_line(line):
    pass # do whatever you want with a line here

for line in open("myfile.txt"):
    handle_line(line)
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.