将选项卡从文本文件划定到python中的2个变量时出错
我有一个文本文件,其中标签将数据划分为2个语言翻译,如下所示;
to the regimes thanthrayanta
according to the anuwa
great maha
situation thathwaya
parabraman parabrahman
two of the two dwithwayan
on a matha
depends randa
exist pawathee
he ohu
我试图将这些数据如下以下,
# Read the file and split into lines
lines = open('old data/eng-sin.txt' % (lang1, lang2), encoding='utf-8').\
read().strip().split('\n')
但是当我运行代码时,我会收到一个错误;
TypeError: not all arguments converted during string formatting
当我搜索错误时,我得到了一个答案,因为使用的%被折旧,新方法是使用。形式,但仍然无法解决问题。请帮助解决此问题
I have a text file which has tab delimated data with 2 language translations as follows;
to the regimes thanthrayanta
according to the anuwa
great maha
situation thathwaya
parabraman parabrahman
two of the two dwithwayan
on a matha
depends randa
exist pawathee
he ohu
I am trying to get those data as follows,
# Read the file and split into lines
lines = open('old data/eng-sin.txt' % (lang1, lang2), encoding='utf-8').\
read().strip().split('\n')
But when I run the code, I get an error as ;
TypeError: not all arguments converted during string formatting
As I searched the error I got an answer as the % used is depreciated and new way is to use .formate but still it doesn't solve the issue. Please help to fix this issue
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
无论如何,这是不起作用的,因为您可以拥有空格,因此,例如,您将获得
lang1
='to'''和lang2
='the'the'''''。您可以做这样的事情:
Anyway this wouldn't work since you can have spaces, so for example you would obtain
lang1
= 'to' andlang2
= 'the' in the first line.You could do something like this: