我有一个Python script
调用 aPerl script
来解析文件。解析后,PERL
脚本生成一个输出,该输出将在脚本中加载到 MySQL 数据库Python
。
Python 脚本如下:
pipe = subprocess.Popen(["perl", "./parseGeneticCode.pl"], stdin=subprocess.PIPE)
pipe.stdin.close()
pipe = subprocess.Popen(["perl", "./makeTaxon.pl"], stdin=subprocess.PIPE)
pipe.stdin.close()
#Load taxon.out (output of makeTaxon.pl) in the database
sql10 = """LOAD DATA LOCAL INFILE 'gene_code.out' INTO TABLE geneticcode FIELDS TERMINATED BY '\t' OPTIONALLY ENCLOSED BY '"' LINES TERMINATED BY '\n' (ncbi_taxon_ID, parent_ID, taxon_name, taxon_strain, rank, geneticcode_ID, mitochondrial_geneticcode_ID);"""
try:
c.execute(sql10)
conn.commit()
print "\nDone uploading in taxon\n"
except StandardError, e:
print e
conn.rollback()
conn.close()
sql9 = """LOAD DATA LOCAL INFILE 'taxon.out' INTO TABLE taxon FIELDS TERMINATED BY '\t' OPTIONALLY ENCLOSED BY '"' LINES TERMINATED BY '\n' (ncbi_taxon_ID, parent_ID, taxon_name, taxon_strain, rank, geneticcode_ID, mitochondrial_geneticcode_ID);"""
try:
c.execute(sql9)
conn.commit()
print "\nDone uploading in taxon\n"
except StandardError, e:
print e
conn.rollback()
conn.close()
这些文件:taxon.out
和gene_code.out
由 perl 脚本创建。但是我的 Python 脚本给出了一个错误:
(2, "File 'taxon.out' not found (Errcode: 2)")
(0, '')
Traceback (most recent call last):
File "common_data.py", line 247, in <module>
conn.rollback()
_mysql_exceptions.OperationalError: (2006, 'MySQL server has gone away')
两个文件gene_code.out
都没有taxon.out
上传。