0

それぞれ別の行に 10 行を生成するスクリプトがあります。行ではなく、10列を生成したい。

    import csv
    import os
    import random
    for dirname, dirnames, filenames in os.walk(r"C:/Users/s/Desktop/filme/"):
        for subdirname in dirnames:
        foldere_filme = os.path.join(dirname, subdirname)
        numarul_folderelor = foldere_filme.replace("C:/Users/s/Desktop/filme/", "")
        print numarul_folderelor #1,2,3,4,5...
        root_text = "C:/Users/s/Desktop/text/tags"+numarul_folderelor+".csv"
        fisier_text_tags = csv.writer(open(root_text,'wb'))
        for filenames in os.listdir(foldere_filme):
            tags = filenames.replace("<SP>", " ").replace(".avi", "")
            test = ['blah '+varible+' test, blah '+varible+' aaaaah clip, blah '+varible+' putlocker, download '+varible+' clip',
                    'blah '+varible+' free tuttiing, blah '+varible+' clip free, blah '+varible+' test clip, download '+varible+' aaaaah clip',
                    'blah '+varible+' 2012, blah '+varible+' test free, download '+varible+' 2012 clip, free tuttiing '+varible+'',
                    'blah '+varible+' free aaaaah clip, blah '+varible+' test 2012, where to blah '+varible+', '+varible+' aaaaah clip test',
                    'strem '+varible+' test free, blah '+varible+' free 2012, blah '+varible+' test for free, '+varible+' aaaaah clip test',
                    'putlocker 2012, blah '+varible+' free, download '+varible+' test, blah test '+varible+' for free, free clip tuttiing']
            random.shuffle(test)
            fisier_text_tags.writerow(test[0:1])
4

2 に答える 2

0

writerow複数の列を書き込むために、iterableをに渡すことができます。

writer.writerow(['hello', 'world'])

そのコードは、ファイルに書き込まれるときにこのcsvドキュメントを生成します。

hello,world
于 2012-11-12T10:33:45.380 に答える
0
import csv
    import os
    import random
    for dirname, dirnames, filenames in os.walk(r"C:/Users/s/Desktop/filme/"):
        for subdirname in dirnames:
        foldere_filme = os.path.join(dirname, subdirname)
        numarul_folderelor = foldere_filme.replace("C:/Users/s/Desktop/filme/", "")
        print numarul_folderelor #1,2,3,4,5...
        root_text = "C:/Users/s/Desktop/text/tags"+numarul_folderelor+".csv"
        fisier_text_tags = csv.writer(open(root_text,'wb'))

        row_test = []

        for filenames in os.listdir(foldere_filme):
            tags = filenames.replace("<SP>", " ").replace(".avi", "")
            test = ['blah '+varible+' test, blah '+varible+' aaaaah clip, blah '+varible+' putlocker, download '+varible+' clip',
                    'blah '+varible+' free tuttiing, blah '+varible+' clip free, blah '+varible+' test clip, download '+varible+' aaaaah clip',
                    'blah '+varible+' 2012, blah '+varible+' test free, download '+varible+' 2012 clip, free tuttiing '+varible+'',
                    'blah '+varible+' free aaaaah clip, blah '+varible+' test 2012, where to blah '+varible+', '+varible+' aaaaah clip test',
                    'strem '+varible+' test free, blah '+varible+' free 2012, blah '+varible+' test for free, '+varible+' aaaaah clip test',
                    'putlocker 2012, blah '+varible+' free, download '+varible+' test, blah test '+varible+' for free, free clip tuttiing']
            random.shuffle(test)

            row_test.append(test[0])

       fisier_text_tags.writerow(row_test)
于 2012-11-12T10:27:21.213 に答える