Created
July 31, 2018 07:32
-
-
Save simecek/221382a3266e0455c8a05537d23b3c75 to your computer and use it in GitHub Desktop.
Print is a function now.ipynb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"nbformat": 4, | |
"nbformat_minor": 0, | |
"metadata": { | |
"colab": { | |
"name": "Print is a function now.ipynb", | |
"version": "0.3.2", | |
"provenance": [], | |
"collapsed_sections": [], | |
"include_colab_link": true | |
}, | |
"kernelspec": { | |
"name": "python3", | |
"display_name": "Python 3" | |
} | |
}, | |
"cells": [ | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "view-in-github", | |
"colab_type": "text" | |
}, | |
"source": [ | |
"[View in Colaboratory](https://colab.research.google.com/gist/simecek/221382a3266e0455c8a05537d23b3c75/print-is-a-function-now.ipynb)" | |
] | |
}, | |
{ | |
"metadata": { | |
"id": "8rx2dUEkQEvX", | |
"colab_type": "text" | |
}, | |
"cell_type": "markdown", | |
"source": [ | |
"## Print is a function now" | |
] | |
}, | |
{ | |
"metadata": { | |
"id": "lsX2jp7-M8HH", | |
"colab_type": "code", | |
"colab": {} | |
}, | |
"cell_type": "code", | |
"source": [ | |
"import builtins\n", | |
"_print = builtins.print # store the original print function\n", | |
"\n", | |
"def print(*args, **kargs):\n", | |
" # do something useful, e.g. store output to some file\n", | |
" nargs = (*args, \"\\nNumber of arguments:\", len(args))\n", | |
" _print(*nargs, **kargs)" | |
], | |
"execution_count": 0, | |
"outputs": [] | |
}, | |
{ | |
"metadata": { | |
"id": "eoGjCeKRNKyK", | |
"colab_type": "code", | |
"colab": { | |
"base_uri": "https://localhost:8080/", | |
"height": 51 | |
}, | |
"outputId": "bc3ae4a1-b6bc-4cbf-d8cf-77c6afcc7f7f" | |
}, | |
"cell_type": "code", | |
"source": [ | |
"print(\"One\", \"Two\", \"Three\")" | |
], | |
"execution_count": 20, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"text": [ | |
"One Two Three \n", | |
"Number of arguments: 3\n" | |
], | |
"name": "stdout" | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"id": "LYuElFZKPwvs", | |
"colab_type": "text" | |
}, | |
"cell_type": "markdown", | |
"source": [ | |
"Read more tips about `print` in Python 3 from https://github.com/arogozhnikov/python3_with_pleasure#print-is-a-function-now." | |
] | |
} | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://twitter.com/python_tip/status/1024912431695454208