- Learn Programming in Python with Cody Jackson
- Cody Jackson
- 484字
- 2021-06-10 19:06:07
Using the IPython shell
The default Python shell is fine, but there are alternatives. The most popular option is to install the IPython shell from https://ipython.org. This is also included with the Anaconda distribution, as well as a number of supporting tools that enhance the development experience.
IPython provides a number of enhancements to the regular interactive Python experience, such as:
- Syntax-highlighted interactive shells
- Web-based notebooks that support multimedia output
- Interactive visualizations
- Interactive parallel application development
- Tab completion
- Object exploration
- Magic functions
- Command history
- Direct implementation of shell commands
The following screenshot demonstrates how the IPython shell differs from the default Python shell. The first thing that is most noticeable is that there is now color within the Python commands. Keywords, errors, and so on are all shown with different colors, easily highlighting different parts of the code.
In addition, each line has its own line number associated with it, rather than the >>> symbol. Lines one and five show that, when necessary, IPython will provide an associated output result if the input command requires it.
Lines six and seven show how IPython can call Bash shell commands directly, in this case pinging a website and printing the current directory, respectively. Because of this ability, some programmers treat IPython as an alternative to the default command shell on *nix systems:
However, there is an alternative to using IPython in this manner: the Xonsh shell, found at https://xon.sh. Depending on your preference, it is pronounced using the Greek letter Chi ("Χ"), to sound like "conch," or with a "Z," to sound like "zonsh."
Xonsh is built on Python 3.4 and includes Bash shell functions; it is designed to improve on perceived problems with Bash, as well as making the lives of Python programmers easier. This is because Xonsh essentially replaces the Bash shell with Python, allowing the use of Python code directly at the command line without having to invoke a Python interactive prompt. It also means that Python code in Xonsh has direct access to the underlying OS processing and filesystems, allowing the user to never have to drop back to Bash to interact with the OS.
If you look back through the previous screenshots, you'll note that at the top of each window, the name "xonsh" was listed. Xonsh functions just like the default Bash shell in *nix; it's only when you start using commands that are associated with Python that you will notice differences.
The following screenshot shows the errors that occur when trying to run Python commands directly with a Bash shell:
The following screenshot shows the same commands successfully functioning within the Xonsh shell:
For the purposes of this book, normal Bash commands will be used when demonstrating OS shell commands, to limit confusion. However, interactive Python sessions will be demonstrated through IPython, rather than the default Python shell.
- 深度實踐OpenStack:基于Python的OpenStack組件開發
- Node.js 10實戰
- 劍指JVM:虛擬機實踐與性能調優
- 程序員面試筆試寶典
- HoloLens Beginner's Guide
- 樂學Web編程:網站制作不神秘
- Getting Started with CreateJS
- 數據結構簡明教程(第2版)微課版
- Magento 1.8 Development Cookbook
- SSM輕量級框架應用實戰
- 青少年學Python(第1冊)
- Android玩家必備
- Python深度學習:模型、方法與實現
- SQL Server實用教程(SQL Server 2008版)
- Scratch3.0趣味編程動手玩:比賽訓練營