{"id":257,"date":"2016-10-15T20:41:14","date_gmt":"2016-10-15T12:41:14","guid":{"rendered":"http:\/\/vinta.ws\/code\/?p=257"},"modified":"2026-03-17T01:12:36","modified_gmt":"2026-03-16T17:12:36","slug":"ipython-another-python-repl-interpreter","status":"publish","type":"post","link":"https:\/\/vinta.ws\/code\/ipython-another-python-repl-interpreter.html","title":{"rendered":"IPython: the Python REPL interpreter"},"content":{"rendered":"<p>IPython is a neat alternative to Python's built-in REPL (Read-Eval-Print Loop) interpreter, also a kernel of Jupyter.<\/p>\n<p>ref:<br \/>\n<a href=\"https:\/\/ipython.org\/\">https:\/\/ipython.org\/<\/a><br \/>\n<a href=\"https:\/\/jupyter.org\/\">https:\/\/jupyter.org\/<\/a><\/p>\n<h2>Useful Commands<\/h2>\n<pre class=\"line-numbers\"><code class=\"language-py\"># cheatsheet\n%quickref\n\n# show details of any objects (including modules, classes, functions and variables)\nrandom?\nos.path.join?\nsome_variable?\n\n# show source code of any objects\nos.path.join??\n\n# show nothing for a function that is not implemented in Python\nlen??\n\n# run some shell commands directly in IPython\npwd\nll\ncd\ncp\nrm\nmv\nmkdir new_folder\n\n# run any shell command with ! prefix\n!ls\n!ping www.google.com\n!youtube-dl\n\n# assign command output to a variable\ncontents = !ls\nprint(contents)<\/code><\/pre>\n<p>ref:<br \/>\n<a href=\"http:\/\/ipython.readthedocs.io\/en\/stable\/interactive\/tutorial.html\">http:\/\/ipython.readthedocs.io\/en\/stable\/interactive\/tutorial.html<\/a><\/p>\n<h2>Magic Functions<\/h2>\n<pre class=\"line-numbers\"><code class=\"language-py\"># list all magic functions\n%lsmagic\n\n# run a Python script and load objects into current session\n%run my_script.py\n\n# run a profiling for multi-line code\n%%timeit\narray = []\nfor i in xrange(100):\n    array.append(i)\n\n# paste multi-line code\n# you might not need them in IPython 5.0+, just paste your code\n%cpaste\n\n# explore objects\n%pdoc some_object\n%pdef some_object\n%psource some_object\n%pfile some_object\n\n# if you call it after hitting an exception, it will automatically open ipdb at the point of the exception\n%debug\n\n# the In object is a list which keeps track of the commands in order\nprint(In)\n\n# the Out object is a dictionary mapping input numbers to their outputs\nprint(Out)\nprint(Out[2], _2)<\/code><\/pre>\n<p>ref:<br \/>\n<a href=\"https:\/\/ipython.readthedocs.io\/en\/stable\/interactive\/magics.html\">https:\/\/ipython.readthedocs.io\/en\/stable\/interactive\/magics.html<\/a><br \/>\n<a href=\"https:\/\/www.safaribooksonline.com\/library\/view\/python-data-science\/9781491912126\/ch02.html\">https:\/\/www.safaribooksonline.com\/library\/view\/python-data-science\/9781491912126\/ch02.html<\/a><\/p>\n<h2>Issues<\/h2>\n<h3>Reload Any Python Module<\/h3>\n<pre class=\"line-numbers\"><code class=\"language-py\">from your.project import your_module\nyour_module.run_shit(123)\n\n# after you made some changes on your_module\nfrom importlib import reload\nreload(your_module)\n\nyour_module.run_shit(123)<\/code><\/pre>\n<p>ref:<br \/>\n<a href=\"https:\/\/stackoverflow.com\/questions\/5364050\/reloading-submodules-in-ipython\">https:\/\/stackoverflow.com\/questions\/5364050\/reloading-submodules-in-ipython<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>IPython is a neat alternative of Python's builtin REPL (Read\u2013Eval\u2013Print Loop) interpreter, also a kernel of Jupyter.<\/p>\n","protected":false},"author":1,"featured_media":270,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[29,2],"class_list":["post-257","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-about-python","tag-debug","tag-python"],"_links":{"self":[{"href":"https:\/\/vinta.ws\/code\/wp-json\/wp\/v2\/posts\/257","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/vinta.ws\/code\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/vinta.ws\/code\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/vinta.ws\/code\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/vinta.ws\/code\/wp-json\/wp\/v2\/comments?post=257"}],"version-history":[{"count":0,"href":"https:\/\/vinta.ws\/code\/wp-json\/wp\/v2\/posts\/257\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/vinta.ws\/code\/wp-json\/wp\/v2\/media\/270"}],"wp:attachment":[{"href":"https:\/\/vinta.ws\/code\/wp-json\/wp\/v2\/media?parent=257"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/vinta.ws\/code\/wp-json\/wp\/v2\/categories?post=257"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/vinta.ws\/code\/wp-json\/wp\/v2\/tags?post=257"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}