T
T
Timebird2016-03-04 04:22:55
Python
Timebird, 2016-03-04 04:22:55

How to loop for functions?

Hello! The question is next.
There is a function that reads data from a file.
Here she is:

def getfreq():
  freq = open('somefile.txt', 'r')
  freqline = freq.readline() #читаем строку из файла
  freqnumber = int(freqline) #переводим строку в число
  return freqnumber

The file contains numbers, one number per line.
In subsequent functions, I take the resulting (first) number, multiply it by an array, etc., etc.
Required: to make it possible to first take the first number and run it through the functions, and then take the second, third, ..., nth number and also run them through the functions.
freq =             getfreq()
func2 =            getsomething(freq)
func3 =            getsomething2(func2, freq)
  ...

It is necessary to set a cycle when calling functions, but how to do it correctly in this case?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
sim3x, 2016-03-04
@sim3x

with open('file.txt') as f:
    for line in f:
       my_num = int(line)
       # do stuff

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question