- 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.
- 微服務設計(第2版)
- Computer Vision for the Web
- Magento 2 Development Cookbook
- 假如C語言是我發(fā)明的:講給孩子聽的大師編程課
- 零基礎學Python數(shù)據(jù)分析(升級版)
- Learning Apache Mahout Classification
- Linux操作系統(tǒng)基礎案例教程
- Extending Puppet(Second Edition)
- jQuery炫酷應用實例集錦
- Visual Basic程序設計習題與上機實踐
- 計算機應用基礎教程(Windows 7+Office 2010)
- Building a Media Center with Raspberry Pi
- Android應用開發(fā)攻略
- 零基礎C語言學習筆記
- 算法訓練營:海量圖解+競賽刷題(入門篇)