I have this function inside a class
def readInput(self, inFile):
with open(inFile, "r") as file:
for line in file:
if (line.split()[0] == "Ks"):
nextLine = next(file)
self.Ks = nextLine.split()[0]
self.thetaS = nextLine.split()[1]
self.thetaR = nextLine.split()[2]
self.alpha = nextLine.split()[3]
self.lamb = nextLine.split()[4]
self.n = nextLine.split()[5]
It basically search for a pattern ("Ks") inside an input file (inFile) to store variable values from the next line of inFile inside instance variables.
There is a lot of repetition in the code and I think it's possible to write that in a clever (and shorter) way.
Any ideas?
The input file looks like this:
### Soil hydraulic properties. Units: m, d
Ks ThetaS ThetaR alpha lambda n
0.128 0.01 0.42 0.84 -1.497 1.441