-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwatch-out-ipython-here-comes-bpython.html
More file actions
27 lines (25 loc) · 12.9 KB
/
watch-out-ipython-here-comes-bpython.html
File metadata and controls
27 lines (25 loc) · 12.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
<!DOCTYPE html>
<html> <head lang=en><meta charset=UTF-8><title>Watch out iPython here comes b(i)python! | EF</title><link href=//cdnjs.cloudflare.com/ajax/libs/font-awesome/4.2.0/css/font-awesome.min.css rel=stylesheet><link href=http://fonts.googleapis.com/css?family=Inconsolata rel=stylesheet type=text/css><link rel=stylesheet href=http://nafiulis.me/theme/css/main.css><link rel=stylesheet href=http://nafiulis.me/theme/css/pygment.css><script src=http://nafiulis.me/theme/js/jquery.min.js></script><script src=http://nafiulis.me/theme/js/main.js></script></head> <body> <!--Heading at the top saying "Engineering Fantasy"--> <div id=header_top> <div class=title> <a href=http://nafiulis.me><span id=engineering>Engineering</span><span id=fantasy>Fantasy</span></a> </div> </div> <button type=button class="js-menu-trigger sliding-menu-button button-nav"> <img src=https://raw.githubusercontent.com/thoughtbot/refills/master/source/images/menu-white.png alt="Menu Icon"> </button> <!--Navigation Bar--> <nav class="js-menu sliding-menu-content"> <span class=section-header>Pages</span> <ul> <li><a href=http://nafiulis.me>Home</a></li> <li><a href=http://nafiulis.me/tags.html>Tags</a></li> <li><a href=http://nafiulis.me/pages/about-me.html>About Me</a></li> </ul> <span class=section-header>Categories</span> <ul> <li><a href=http://nafiulis.me/category/anime.html>Anime</a></li> <li><a href=http://nafiulis.me/category/education.html>Education</a></li> <li><a href=http://nafiulis.me/category/productivity.html>Productivity</a></li> <li><a href=http://nafiulis.me/category/programming.html>programming</a></li> <li><a href=http://nafiulis.me/category/rants.html>rants</a></li> </ul> </nav> <div class="js-menu-screen menu-screen"></div> <!--Main Container--> <div class=container> <!--Top most menu--> <div id=menu> <div class=left> <a href=http://nafiulis.me/feeds/all.atom.xml><i class="fa fa-rss
icon"></i></a> <a href=https://twitter.com/gamesbrainiac><i class="fa fa-twitter icon"></i></a> </div> <div class=center> <h1 class=message>Nafiul Islam on casting spells with code</h1> </div> <div class=right> <a href=https://github.com/gamesbrainiac><i class="fa fa-github icon"></i></a> <a href=http://stackoverflow.com/users/1624921/games-brainiac><i class="fa fa-stack-overflow icon" style="padding-right: 30px"></i></a> </div> </div> <!--Main blog list container--> <div id=blogroll> <div class=article-container> <h1>Watch out iPython here comes b(i)python!</h1> <p class=time>Tuesday, 20 May 2014</p> <div class=article-content> <img alt="Like what you see?" class=align-center src=images/bpython.png> <div class="contents topic" id=table-of-contents> <p class="topic-title first">Table of Contents</p> <ul class=simple> <li><a class="reference internal" href=#getting-started id=id1>Getting Started</a></li> <li><a class="reference internal" href=#a-few-quick-tips id=id2>A Few Quick Tips</a></li> <li><a class="reference internal" href=#sweet-code-completion id=id3>Sweet code completion</a></li> <li><a class="reference internal" href=#don-t-worry-if-you-mess-up id=id4>Don't worry if you mess up</a></li> <li><a class="reference internal" href=#share-your-code-on-the-fly id=id5>Share your code on the fly</a></li> <li><a class="reference internal" href=#contacting-the-team id=id6>Contacting the team</a></li> <li><a class="reference internal" href=#but-what-if-you-wanted-both id=id7>But what if you wanted both?</a></li> <li><a class="reference internal" href=#update id=id8>Update</a></li> </ul> </div> <p>So if you've been using Python for some time now, you've probably heard of <a class="reference external" href=http://ipython.org/ >iPython</a>. This is pretty much the go to shell for most pythonistas who want to get a better command line debug experience. I find <code>ipdb</code> to be a godsend when I'm quickly trying to diagnose the problem.</p> <p>But what about when you're trying to <em>explore</em> a library or even write some code quickly with plenty of auto-completion, or perhaps quickly demonstrate something, you might want to chose <code>bpython</code>. And if you wanted the best of both worlds, both <code>ipython</code> and <code>bpython</code>, there's <code>bipython</code>. But first, lets take a look at what <code>bpython</code> can offer us:</p> <div class=section id=getting-started> <h2><a class=toc-backref href=#id1>Getting Started</a></h2> <p><code>bpython</code> works on <code>*nix</code> systems with ease, for windows users all you need to is use <a class="reference external" href=http://www.lfd.uci.edu/~gohlke/pythonlibs/#curses>this installer</a> to install the package. But <code>*nix</code> users, its much simpler:</p> <div class=highlight><pre><span></span>pip install bpython
</pre></div> <p>In my tests <code>bpython</code> worked with <strong>both python 2 and python 3 as well as pypy</strong> because its written in pure python and the only dependency <code>bpython</code> has is on <code>pygments</code>:</p> <img alt="bpython works on Python 3!" class=align-center src=images/bpython_works_on_3.png> <p>Once you've installed <code>bpython</code>, you can then just involve it from the command line:</p> <img alt="How you start it :)" class=align-center src=images/bpython_start.png> </div> <div class=section id=a-few-quick-tips> <h2><a class=toc-backref href=#id2>A Few Quick Tips</a></h2> <ul class=simple> <li>The first thing I learn to do with any shell or any new software for that matter is how to get out out of it. The best way to get out of <code>bpython</code> is just to hit <code>CTRL</code> + <code>D</code>, and that will take you out.</li> <li><code>bpython</code> will automatically add the contents of your session to your console.</li> <li>You can save you session with <code>CTRL</code> + <code>S</code>.</li> <li>You can clear the <code>bpython</code> screen with <code>CTRL</code> + <code>L</code>.</li> </ul> </div> <div class=section id=sweet-code-completion> <h2><a class=toc-backref href=#id3>Sweet code completion</a></h2> <p>I love code completion. How can you not love something that pretty much writes your code for you? As a person who's always looking out for better tools, <code>bpython</code> hits the spot. It's got the best code completion I've seen in <em>any</em> shell, it even puts <code>fish</code> to shame:</p> <div class="external youtube"><iframe width=640 height=360 src=//www.youtube.com/embed/ghohKayNeds frameborder=0></iframe></div><p>What I love about <code>bpython</code> is how fast the code completion pops up and the way documentation just pops up when you want to use a function.</p> </div> <div class=section id=don-t-worry-if-you-mess-up> <h2><a class=toc-backref href=#id4>Don't worry if you mess up</a></h2> <p>When I'm trying to reproduce something on the command line, I often make mistakes (although with <code>bpython</code>'s code completion it's a lot harder to do). I'm trying to import <code>asyncio</code> here:</p> <div class=highlight><pre><span></span><span class=o>>>></span> <span class=kn>import</span> <span class=nn>asycnio</span>
<span class=n>Traceback</span> <span class=p>(</span><span class=n>most</span> <span class=n>recent</span> <span class=n>call</span> <span class=n>last</span><span class=p>):</span>
<span class=n>File</span> <span class=s2>"<input>"</span><span class=p>,</span> <span class=n>line</span> <span class=mi>1</span><span class=p>,</span> <span class=ow>in</span> <span class=o><</span><span class=n>module</span><span class=o>></span>
<span class=ne>ImportError</span><span class=p>:</span> <span class=n>No</span> <span class=n>module</span> <span class=n>named</span> <span class=s1>'asycnio'</span>
</pre></div> <p>Now, when you're trying to send a console session to someone, these mistakes are not only annoying but also can get in the way of the person trying to help you, so you can just redo the last line with <code>CTRL</code> + <code>r</code>:</p> <div class="external youtube"><iframe width=640 height=360 src=//www.youtube.com/embed/JSYV9h2Mrr4 frameborder=0></iframe></div><p>Please note that this does not negate what you did, it just clears the screen of the last command that you input. So if you imported <code>datetime</code>, but you actually wanted to import <code>requests</code> (yes, I don't know how to spell but bear with me), then <code>datetime</code> will still be usable from the shell:</p> <div class="external youtube"><iframe width=640 height=360 src=//www.youtube.com/embed/_h9BlN4s_wM frameborder=0></iframe></div></div> <div class=section id=share-your-code-on-the-fly> <h2><a class=toc-backref href=#id5>Share your code on the fly</a></h2> <p>If you want to share your session with someone, you can do that in just one keystroke <code>F8</code>. It will prompt you for confirmation, after which you can view your paste on bpython's code hosting site:</p> <img alt=Pastebin class=align-center src=images/bpython_natsu.png> <p>After you've said yes to the prompt, it will generate a link for you, so <a class="reference external" href=http://bpaste.net/show/NnLYEXislfYLVZTKVgAE/ >this</a> is the one it generated for my session.</p> </div> <div class=section id=contacting-the-team> <h2><a class=toc-backref href=#id6>Contacting the team</a></h2> <p>These are just <em>some</em> of the awesome things you can do with <code>bpython</code>. There's probably more. I don't know them all since I'm still exploring what you can do with it.</p> <p>You can find out more about by talking to the guys on their <code>irc</code> in <code>#bpython</code> on <code>irc.freenode.net</code>. Find out more about the community around <code>bpython</code> <a class="reference external" href=http://bpython-interpreter.org/community/ >here</a>.</p> <p>I initially though that <code>bpyhon</code> was not properly maintained, but if you take a look at <a class="reference external" href=https://bitbucket.org/bobf/bpython>their project page</a>, it seems that its being kept up to date:</p> <img alt="Its up to date :)" class=align-center src=images/bpython_bb.png> </div> <div class=section id=but-what-if-you-wanted-both> <h2><a class=toc-backref href=#id7>But what if you wanted both?</a></h2> <p>Well you'd have to use <code>bipython</code> then. Its still in the works, and there's no proper highlighting for errors right now like in <code>ipython</code>, but its heading towards being a package that unifies both <code>ipython</code> and <code>bpython</code>. So, you need to install <code>ipython</code>, <code>bipython</code>:</p> <div class=highlight><pre><span></span>pip install ipython bipython
</pre></div> <p>And you're done with the installations but running <code>bipython</code> is not as simple. At this time, <code>bipython</code> does not work with python 3, but it does work with python 2. Have a look:</p> <div class="external youtube"><iframe width=640 height=360 src=//www.youtube.com/embed/w9JcgM2YN4I frameborder=0></iframe></div></div> <div class=section id=update> <h2><a class=toc-backref href=#id8>Update</a></h2> <p><em>Last Updated on 15 Nov 2014 1:11 PM</em></p> <p>Information about <tt class="docutils literal">bipython</tt> added.</p> </div> </div> </div> <div class=post-meta><span class=meta-type>Category: </span> <span><a href=http://nafiulis.me/category/programming.html>programming</a></span> <span class=meta-type> Tags: </span> <span> <a href=http://nafiulis.me/tag/ipython.html>ipython</a>, <a href=http://nafiulis.me/tag/bpython.html>bpython</a>, <a href=http://nafiulis.me/tag/python-shell.html>python-shell</a>, <a href=http://nafiulis.me/tag/python.html>python</a>, <a href=http://nafiulis.me/tag/ide.html>ide</a> </span> </div> <div id=disqus_thread style="margin-top: 10px; margin-left: 20px; margin-right: 20px;"></div> <script type=text/javascript>
/* * * CONFIGURATION VARIABLES: EDIT BEFORE PASTING INTO YOUR WEBPAGE * * */
var disqus_shortname = 'nafiulisme'; // required: replace example with your forum shortname
/* * * DON'T EDIT BELOW THIS LINE * * */
(function() {
var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
dsq.src = '//' + disqus_shortname + '.disqus.com/embed.js';
(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
})();
</script> <noscript>Please enable JavaScript to view the <a href=http://disqus.com/?ref_noscript>comments powered by Disqus.</a></noscript> </div> <!--Footer--> <div id=footer> <footer> Code examples licenced under MIT License <br> Copyright <i class="fa fa-copyright"></i> 2018 Quazi Nafiul Islam </footer> </div> </div> <script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-55554110-1', 'auto');
ga('send', 'pageview');
</script> </body> </html>