“Project Euler is a series of challenging mathematical/computer programming problems that will require more than just mathematical insights to solve. Although mathematics will help you arrive at elegant and efficient methods, the use of a computer and programming skills will be required to solve most problems.“
I heard about it some time ago but I looked at it just two days ago. It’s fun! :) If you learn (know) Python and you like to solve mathematical problems with your computer then try Project Euler.
Maybe I will start posting here my solutions.
Your script produces some output to the standard output and you want to redirect it to a file. For instance, you want to suppress the output to
/dev/null. However, you want to do this redirection from your script and not in the shell.
Add the following lines to the beginning of your script (before the first
old_stdout = sys.stdout sys.stdout = open(os.devnull, 'w')
Of course, instead of
os.devnull you can specify a normal text file too. To restore printing to stdout, point
In this thread you will see a solution for redirecting the stdout to a string.
“bpython is a fancy interface to the Python interpreter for Unix-like operating systems (I hear it works fine on OS X). It is released under the MIT License. It has the following features:
- In-line syntax highlighting.
- Readline-like autocomplete with suggestions displayed as you type.
- Expected parameter list for any Python function.
- “Rewind” function to pop the last line of code from memory and re-evaluate.
- Send the code you’ve entered off to a pastebin.
- Save the code you’ve entered to a file.
- Python 3 support.
sudo apt-get install bpython
Tip: add the following line to your
Then you can start the bpython interpreter with “
p“. Short and simple :)
- classic “python” interpreter
“Marakana‘s raison d’être is to help people get better at what they do professionally. We accomplish this by organizing software training courses (both public and private) as well as publishing learning resources, sharing knowledge from industry leaders, providing a place to share useful tidbits and supporting the community. Our focus is open source software.”
Their Python videos are here.
You want to make a JSON file (string) human-readable.
curl -s http://www.reddit.com/r/nsfw/.json | python -mjson.tool
For some more alternatives please refer to this post.
Another way is to use jq, a powerful command-line tool for querying JSON files.