2016-09-19 3 views
0

に "メイン" 機能をapplyinのCSV出力として、私が言って、Pythonで、main関数を適用してきた:保存のpython

[['This is my car not yours'], ['He answered me sorry'], ['no problem'], ['\nYou are crazy'], ['All cars are the same'], etc...] 

def main(): 
    "some code here" 

if __name__ == '__main__': 
    main() 

は、その後、私はこのような結果を得ます

私は結果をtxtとcsvファイルに保存して、後で同じ構造を保持するようにしたい:二重カッコ、単語、カンマなど。どうすればいいですか?前もって感謝します。この

+0

あなたはhttps://docs.python.org/3/library/csv.html それはcsvファイルにリストを変換することができますのpythonのcsvモジュールを使用することができます –

+1

を直接 "python"として印刷するには、pretty print(pprint)を使用してください。https://docs.python.org/3/library/pprint.html もう一つの可能​​性はpython urscript.py> data.txtです標準出力をファイルにリダイレクトして使用します。 –

+0

'main()'関数がcsvと正直に関係していることを理解していません... – martin

答えて

0

希望は、あなたが望んでいたものです:

def main(): 
    return [['This is my car not yours'], ['He answered me sorry'], ['no problem'], ['\nYou are crazy'], ['All cars are the same']] 

if __name__ == '__main__': 
    with open('output.txt', 'w') as f: 
     a = ('').join(str(main())) 
     f.write(a) 
+0

あなたのコードを適用した後は、Borisは空です。どのように改善する? – mlosada

+0

私はちょうど私の答えを編集しました。 'print'文を' return'に変更してください。 main()内のコードがわからないので、これは私の最高の推測です。 – zipa