AttributeError: '_io.TextIOWrapper' object has no attribute 'lower' for txt file
<p>Here is my code (A pig <strong>Latin translator</strong> from a text file):   </p>

<pre><code>f = open('Assignment_4.txt', 'r+')

for line in f:
    print(line)

def pigLatin():
    var = 'ay'
    wordL = f.lower()
    firstLetter = wordL[0]
    pigLatin = wordL + firstLetter + var
    pigLatin = pigLatin[1:]
    print(pigLatin)
</code></pre>

<p>It works for defined strings but won't for the file. Help is appreciated!</p>

<p><strong>Points:</strong></p>

<ul>
<li><code>lower()</code> works with string. You are trying to use with file handle <code>f</code>. That's why you are getting this error. </li>
<li>Also, after reading file line by line, you should call <code>pigLatin()</code> for each line as <code>pigLatin(line)</code>. So, now , pigLatin() function expects one argument.</li>
<li>Also, close the file at the end as <code>f.close()</code>.  It will be if you use <code>with</code> statement to open file.</li>
</ul>

<p><strong>Code with comments inline:</strong></p>

<pre><code>def pigLatin(stuff_to_be_changed):
    var = 'ay'
    wordL = stuff_to_be_changed.lower()
    firstLetter = wordL[0]
    pigLatin = wordL + firstLetter + var
    pigLatin = pigLatin[1:]
    print(pigLatin)


#For string

string =  "I am to change"
#Call function
pigLatin(string)

f = open('Assignment_4.txt', 'r+')

#For file
for line in f:
    print(line)
    #Call function
    pigLatin(line)

#Close the file
f.close()
</code></pre>

python