TranslateProject/sources/tech/20180425 Enhance your Python with an interactive shell.md
2018-05-03 08:58:45 +08:00

4.2 KiB
Raw Blame History

translating---geekpi

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. Its 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 doesnt 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


via: https://fedoramagazine.org/enhance-python-interactive-shell/

作者:Clément Verna 选题:lujun9972 译者:译者ID 校对:校对者ID

本文由 LCTT 原创编译,Linux中国 荣誉推出