
Pythonを計算機として使い、すべてをファイルに出力したいのですが
mamboleo@mamboleo-K56CB:~$ python
Python 2.7.5+ (default, Sep 19 2013, 13:48:49)
[GCC 4.8.1] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> 5**555 > output
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'output' is not defined
エラーが発生し、結果をテキスト ファイルに出力する方法が見つかりません。2>
動作しません。
答え1
out = open("output.txt", "w")
out.write(str(5*5+9))
out.close()
それを実行するには、Python ファイル オブジェクトを開く必要があります。Python スクリプトを実行する場合は、「>」を使用できます。
python test.py > output