我有一个名为TBXTools的文件,我正在尝试使用
from TBXTools import *
e=TBXTools()
看起来很简单,不是吗。但当我运行它时,我得到了以下错误:
AttributeError:“TBXTools”没有属性“cur”
现在我有了这个方法,就在“TBXTools”文件中。那怎么了?请帮忙
def load_sl_tl_corpus(self,slcorpusfile, tlcorpusfile, encoding="utf-8"):
'''Loads a bilingual corpus in Moses format (that is, in two independent files. It expects one segment per line.'''
self.slcf=codecs.open(slcorpusfile,"r",encoding=encoding)
self.tlcf=codecs.open(tlcorpusfile,"r",encoding=encoding)
self.sl_data=[]
self.tl_data=[]
self.continserts=0
while 1:
self.sl_segment=self.slcf.readline()
if not self.sl_segment:
break
self.tl_segment=self.tlcf.readline()
self.continserts+=1
self.max_id_corpus+=1
self.sl_record=[]
self.tl_record=[]
self.sl_segment=self.sl_segment.rstrip()
self.tl_segment=self.tl_segment.rstrip()
self.sl_record.append(self.max_id_corpus)
self.tl_record.append(self.max_id_corpus)
self.sl_record.append(self.sl_segment)
self.tl_record.append(self.tl_segment)
self.sl_data.append(self.sl_record)
self.tl_data.append(self.tl_record)
if self.continserts==self.maxinserts:
self.cur.executemany("INSERT INTO sl_corpus (id, segment) VALUES (?,?)",self.sl_data)
self.cur.executemany("INSERT INTO tl_corpus (id, segment) VALUES (?,?)",self.tl_data)
self.sl_data=[]
self.tl_data=[]
self.continserts=0
with self.conn:
self.cur.executemany("INSERT INTO sl_corpus (id, segment) VALUES (?,?)",self.sl_data)
self.cur.executemany("INSERT INTO tl_corpus (id, segment) VALUES (?,?)",self.tl_data)
self.conn.commit()
我这样称呼它:
e.load_sl_corpus("Main corpus.txt")
注意:我试图通过python -tt
运行它,但得到了相同的错误
以下是我输入文件中的一个小示例:
清除返回的值占零售销售额的百分比。
采购订单每次在此位置收到此项目时的预计到岸成本,或主要供应商成本,具体取决于销售系统选项。
采购订单每次在此位置收到此项目时的预计到岸成本,或主要供应商成本,具体取决于销售系统选项。
正常销售导致的原计划降价金额的零售价值。
报告期开始时某一地点所有库存状态代码中的不可用清关库存数量。
在考虑退货和取消后,流入净销售额的需求百分比。返回和取消的总和除以需求销售零售价值,从1中减去,得到逆百分比值。
@RICP2@-收缩非Clr成本金额
客户细分职业代码
文本或非数值的灵活事实列31
编辑:
我已经创建了一个连接数据库的函数,请查看以下内容:
def create_project(self,project_name,sl_lang,tl_lang="null",overwrite=False):
'''Opens a project. If the project already exists, it raises an exception. To avoid the exception use overwrite=True. To open existing projects, use the open_project method.'''
if os.path.isfile(project_name) and not overwrite:
raise Exception("This file already exists")
else:
if os.path.isfile(project_name) and overwrite:
os.remove(project_name)
self.sl_lang=sl_lang
self.tl_lang=tl_lang
self.conn=sqlite3.connect(project_name)
self.cur = self.conn.cursor()
self.cur2 = self.conn.cursor()
with self.conn:
self.cur = self.conn.cursor()
在构造函数中使用属性
cur
之前,需要初始化该属性。 请在这里也包括__init__()
函数定义相关问题 更多 >
编程相关推荐