Question

Im coding a pig latin converter that askes to user to for a file name and opens it that converts all the words into pig latin and changes all vowles from a letter to "*"

VOWELS = ("a", "e", "i", "o", "u", "A", "E", "I", "O", "U")

f = open('textfile', 'w')

line = f

words =  line.split()

count = 0

    for word in words:
        for vowel in VOWELS:
            if vowel in word:
                # Find the first vowel that comes up
                i = word.find(vowel)
                #Found the first one, stop there!
                break
            else:
                # Set the error value again
                i = -1


def find_vowel(word):
    # This is from 0 to the length of the word
    for i in range(len(word)):
       if word[i] in VOWELS: 
         return i
    # Return an error value if there are not any (which solves another problem too!)
    return -1

    for vowel in file:
        if curlet.strip()==vowels:
            print('*')
    else:
        print (curlet,end='')

right now Im getting this error:

"Traceback (most recent call last):
  File "D:/Python/Projects/piglatin1.py", line 12, in <module>
    words =  line.split()
AttributeError: '_io.TextIOWrapper' object has no attribute 'split'"
Was it helpful?

Solution

line is f. f is your file. You can't split a file, you can only split strings. Do you mean line = f.read()? line would then be a misnomer, since it would be all the data from the file, but you don't have anything in your code that would loop over the lines and process them one at a time.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top