Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Learn Programming in Python with Cody Jackson

You're reading from   Learn Programming in Python with Cody Jackson Grasp the basics of programming and Python syntax while building real-world applications

Arrow left icon
Product type Paperback
Published in Nov 2018
Publisher Packt
ISBN-13 9781789531947
Length 304 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
Cody Jackson Cody Jackson
Author Profile Icon Cody Jackson
Cody Jackson
Arrow right icon
View More author details
Toc

Table of Contents (14) Chapters Close

Preface 1. The Fundamentals of Python 2. Data Types and Modules FREE CHAPTER 3. Logic Control 4. Functions and Object Oriented Programming 5. Files and Databases 6. Application Planning 7. Writing the Imported Program 8. Automated Software Testing 9. Writing the Fueling Scenario 10. Software Post-Production 11. Graphical User Interface Planning 12. Creating a Graphical User Interface 13. Other Books You May Enjoy

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:

IPython example

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:

Bash command errors

The following screenshot shows the same commands successfully functioning within the Xonsh shell:

Xonsh commands

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.

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image