Skip to content

Instantly share code, notes, and snippets.

@simecek
Created July 31, 2018 07:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save simecek/221382a3266e0455c8a05537d23b3c75 to your computer and use it in GitHub Desktop.
Save simecek/221382a3266e0455c8a05537d23b3c75 to your computer and use it in GitHub Desktop.
Print is a function now.ipynb
Display the source blob
Display the rendered blob
Raw
{
"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."
]
}
]
}
@simecek
Copy link
Author

simecek commented Oct 11, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment