0

シンプルなCSV outFileを作成するPythonでこの関数を使用していますが、Windowsエクスプローラーで保存するディレクトリを選択したいのですが、関数は次のとおりです。

def exporter():
    name_of_file="export"
    l = [[1, 2], [2, 3], [4, 5]]
    completeName = os.path.abspath("C:\temp\%s.csv" % name_of_file)
    out = open(completeName,"w")
    for row in l:
        for column in row:
            out.write('%d;' % column)
            out.write('\n')
        out.close()

    QObject.connect(export, SIGNAL('clicked()'),exporter)

export は QPushButton です、ありがとう!

4

1 に答える 1

0
def exporter(directory='C:\temp\\'):
    name_of_file = "export"
    l = [[1, 2], [2, 3], [4, 5]]
    completeName = os.path.abspath("C:/temp/%s.csv" % name_of_file)
    full_path = '%(directory)s\%(name_of_file)s.csv' % locals()
    out = open(full_path, "w")
    for row in l:
        for column in row:
            out.write('%d;' % column)
            out.write('\n')
        out.close()

    QObject.connect(export, SIGNAL('clicked()'),exporter)

このようなものがうまくいきます。パスを引数として渡すだけです。

于 2013-07-31T09:21:13.017 に答える