File's Data keeps getting overwritten by function
<p>for some reason I am running into an issue where my function call seems to be overwriting the data read in from the file without me asking it to. I am trying to get the sum of the original list but I keep getting the sum of the squared list. </p>

<p><strong>CODE:</strong></p>

<pre><code>def toNumbers(strList):
    for i in range(len(strList)):
        strList[i] = strList [int(i)]
    return strList


def squareEach(nums):
    for i in range(len(nums)):
        nums[i] = eval(nums[i])
        nums[i] = nums[i]**2
    return nums




def sumList(nums):
    b = sum(nums)
    return b





def main():
    file=open("numbers.txt","r").readline().split(" ")
    print(str(squareEach(file)))
    print(str(sumList(file)))
</code></pre>

<p>I am not sure whether i am helping . But whatever you are trying to do can be done as follows</p>

<pre><code>file=open("numbers.txt","r").readline().split(" ")
print ([int (m)**2 for m in file])
print (sum([int(m) for m in file]))
</code></pre>

<p>And if you want functions</p>

<pre><code>def squareEach(file):
    print ([int (m)**2 for m in file])
def sumList(file):
    print (sum([int(m) for m in file]))


file=open("numbers.txt","r").readline().split(" ")
squareEach(file)
sumList(file)   
</code></pre>

python file-io