Python mysql使用管道加载文件

Python mysql使用管道加载文件,python,mysql,Python,Mysql,如何使用管道来使用python加载数据填充?下面的代码似乎不起作用。本地infle需要一个文件,因此不确定它是否因此而失败 cat = Popen(["cat /Users/test/filename.out"], stdout=PIPE, bufsize=-1, shell=True) load = """load data local infile - into table %s fields terminated by '|' lines terminated by '\\n';""" %

如何使用管道来使用python加载数据填充?下面的代码似乎不起作用。本地infle需要一个文件,因此不确定它是否因此而失败

cat = Popen(["cat /Users/test/filename.out"], stdout=PIPE, bufsize=-1, shell=True)
load = """load data local infile - into table %s fields terminated by '|' lines terminated by '\\n';""" % (tablename)

with conn:
    cursor = conn.cursor()
    for line in cat.stdout:
        cursor.execute(load.stdin.write(line))
cat.stdout.close()
cat.wait()
load.stdin.close()
load.wait()

为什么要使用
cat
?为什么要使用shell?
cat
仅用于表示。在上面的示例中,我使用了一个数据流,而不是
cat