【发布时间】:2014-02-22 16:32:44
【问题描述】:
我正在编写一个猪拉丁语转换器,它要求用户输入文件名并打开它,将所有单词转换为猪拉丁语并将所有元音从字母更改为“*”
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='')
现在我收到此错误:
"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'"
【问题讨论】:
标签: python python-3.x python-3.2