
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