Enhance your Python with an interactive shell

The Python programming language has become one of the most popular languages used in IT. One reason for this success is it can be used to solve a variety of problems. From web development to data science, machine learning to task automation, the Python ecosystem is rich in popular frameworks and libraries. This article presents some useful Python shells available in the Fedora packages collection to make development easier.

Python Shell

The Python Shell lets you use the interpreter in an interactive mode. It’s very useful to test code or try a new library. In Fedora you can invoke the default shell by typing python3 in a terminal session. Some more advanced and enhanced shells are available to Fedora, though.

IPython

IPython provides many useful enhancements to the Python shell. Examples include tab completion, object introspection, system shell access and command history retrieval.  Many of these features are also used by the Jupyter Notebook , since it uses IPython underneath.

Install and run IPython

dnf install ipython3
ipython3

Using tab completion prompts you with possible choices. This features comes in handy when you use an unfamiliar library.

If you need more information, use the documentation by typing the ? command. For more details, you can use the ?? command.

Another cool feature is the ability to execute a system shell command using the ! character. The result of the command can then be referenced in the IPython shell.

A comprehensive list of IPython features is available in the official documentation.

bpython

bpython doesn’t do as much as  IPython, but nonetheless it provides a useful set of features in a simple and lightweight package. Among other features, bpython provides:

  • In-line syntax highlighting
  • Autocomplete with suggestions as you type
  • Expected parameter list
  • Ability to send or save code to a pastebin service or file

Install and run bpython

dnf install bpython3
bpython3

As you type, bpython offers you choices to autocomplete your code.

When you call a function or method, the expected parameters and the docstring are automatically displayed.

Another neat feature is the ability to open the current bpython session in an external editor (Vim by default) using the function key F7. This is very useful when testing more complex programs.

For more details about configuration and features, consult the bpython documentation.

Conclusion

Using an enhanced Python shell is a good way to increase productivity. It gives you enhanced features to write a quick prototype or try out a new library. Are you using an enhanced Python shell? Feel free to mention it in the comment section below.


Photo by David Clode on Unsplash

For Developers Using Software

7 Comments

  1. sabino

    great suggestions !!!
    I learned something new.
    Thank you

  2. Dan

    Have you seen xonsh (http://xonsh.org/) ? It’s a shell with the power of Python, very cool.

    (I’m trying to use it as default shell, but I’m stuck when using it in x2go).

    • I did, I try it a while ago and thought it was still a little bit too fresh. Maybe I should give a go again 🙂

  3. Apostolos

    ptipython (uses ipython) also offers handy features.

  4. Jon Hannah

    Another great Python 3+ light weight IPython-style REPL is hiss. See https://github.com/sixninetynine/hiss but in pip too!

  5. Cyril

    Just…the image is that of an arboreal pit viper (Tropidolaemus Waglerii?), not a python 😉

Comments are Closed

The opinions expressed on this website are those of each author, not of the author's employer or of Red Hat. Fedora Magazine aspires to publish all content under a Creative Commons license but may not be able to do so in all cases. You are responsible for ensuring that you have the necessary permission to reuse any work on this site. The Fedora logo is a trademark of Red Hat, Inc. Terms and Conditions