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>Your squareEach function modifies the original list which is passed to it.
To see what's going, consider adding a print between your function calls.
<code>
    def main():
        file=open("numbers.txt","r").readline().split(" ")
        print(str(squareEach(file)))
        print(str(file))
        print(str(sumList(file))
</code></p>

<p>EDIT:
The simplest fix would be to use a different list for storing your square numbers inside squareEach function</p>

<pre><code>def squareEach(nums):
    squares = []
    for i in range(len(nums)):
        num = eval(nums[i])
        squares[i] = num**2
    return squares
</code></pre>

<p>There are more efficient ways as suggested in other answers, but in your case, this appears to be the simplest fix.</p>

python file-io