I want to use python as a calculator and output everything into file. But
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 definedIt gives me an error, and I couldn't find how to output my result into text file. 2> does not work either.
1 Answer
out = open("output.txt", "w") out.write(str(5*5+9)) out.close()You have to open python file object to do that. If you run python script, then you can use '>':
python test.py > output 1