尝试通过删除有问题的大写和引号来规范化文本数据
Trying to normalize text data by removing caps and quotation marks having issues
正在尝试删除本地 outputtext.txt 文件中所有引号和大写字母的实例
此代码基于此网站
https://www.thepythoncode.com/article/text-generation-keras-python
sequence_length = 100
BATCH_SIZE = 128
EPOCHS = 30
text = open("outputtext.txt",'r',encoding="utf-8")
text = text.lower()
text = text.translate(str.maketrans("", "", punctuation))
但是当我运行代码时;较低的功能和翻译功能都 return 错误
lower:AttributeError: '_io.TextIOWrapper' 对象没有属性 'lower'
翻译:AttributeError:'_io.TextIOWrapper'对象没有属性'translate'。您的意思是:'truncate'?
我试过修改读写权限,但似乎不起作用?
文件内容:
Sam" goes "To" the StOre.
读入文件、编辑文件、打印文件内容
with open('outputtext.txt', 'r') as f:
lines = f.readlines()
lines = lines[0].lower().replace('"','')
# output: sam goes to the store.
print(lines)
读入文件、编辑文件、向新文件写入行
with open('outputtext.txt', 'r') as infile:
lines = infile.readlines()
lines = lines[0].lower().replace('"','')
with open('new_outputtext.txt', 'w') as outfile:
lines = outfile.write(lines)
正在尝试删除本地 outputtext.txt 文件中所有引号和大写字母的实例
此代码基于此网站 https://www.thepythoncode.com/article/text-generation-keras-python
sequence_length = 100
BATCH_SIZE = 128
EPOCHS = 30
text = open("outputtext.txt",'r',encoding="utf-8")
text = text.lower()
text = text.translate(str.maketrans("", "", punctuation))
但是当我运行代码时;较低的功能和翻译功能都 return 错误
lower:AttributeError: '_io.TextIOWrapper' 对象没有属性 'lower'
翻译:AttributeError:'_io.TextIOWrapper'对象没有属性'translate'。您的意思是:'truncate'?
我试过修改读写权限,但似乎不起作用?
文件内容:
Sam" goes "To" the StOre.
读入文件、编辑文件、打印文件内容
with open('outputtext.txt', 'r') as f:
lines = f.readlines()
lines = lines[0].lower().replace('"','')
# output: sam goes to the store.
print(lines)
读入文件、编辑文件、向新文件写入行
with open('outputtext.txt', 'r') as infile:
lines = infile.readlines()
lines = lines[0].lower().replace('"','')
with open('new_outputtext.txt', 'w') as outfile:
lines = outfile.write(lines)