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
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Learn Python in 7 Days

You're reading from   Learn Python in 7 Days Begin your journey with Python

Arrow left icon
Product type Paperback
Published in May 2017
Publisher Packt
ISBN-13 9781787288386
Length 280 pages
Edition 1st Edition
Languages
Arrow right icon
Authors (2):
Arrow left icon
Mohit Raj Mohit Raj
Author Profile Icon Mohit Raj
Mohit Raj
Bhaskar N. Das Bhaskar N. Das
Author Profile Icon Bhaskar N. Das
Bhaskar N. Das
Arrow right icon
View More author details
Toc

Table of Contents (12) Chapters Close

Preface 1. Getting Started with Python FREE CHAPTER 2. Type Variables and Operators 3. Strings 4. Lists 5. Dictionary 6. Control Statements and Loops 7. Function and Scope of Variable 8. Modules and Packages 9. File Handling and Exceptions 10. Collections 11. Class and Objects

Notepad++ installation

Notepad++ is one of the easy-to-use text editors and is a free open source software program, which could be easily downloaded from https://notepad-plus-plus.org/. We will be using this text editor to create simple programs.

Python file formats

Every language understands a file format, for example, like the C language file extension is .c likewise java language has a file extension .java. The Python file extension is .py while bytecode file extension is .pyc.

Python interactive shell

Python interactive shell is also known as Integrated Development Environment (IDLE). With the Python installer, two interactive shells are provided: one is IDLE (Python GUI) and the other is Python (command line). Both can be used for running simple programs.

For complex programs and executing large files, the windows command prompt is used, where after the system variables are set automatically, large files are recognized and executed by the system.

The preceding screenshot is what we call Python IDLE, which comes bundled with the Python installation. The next screenshot is of the command line that also comes bundled with the Python installation, or we can simply launch the Python command through the windows command line and get Python command line. For most of our programming instructions, we will be using the Python command line:

System or environment variables

If you remember the installation steps explained earlier, you might be still thinking what are system variables? They are a set of predefined variables, which are available to all programming units. If it's not set, then each and every time you want to run your program or execute a Python file, you will have to manually provide path for each Python executable, but if python.exe is set as a system variable, then the system automatically recognizes your programming instruction and starts executing.

Setting environment variables in Windows

Here, if python.exe is not provided to the path variable, then the system does not recognize python as a command, as shown in the following screenshot:

The Windows command prompt does not recognize python as shown in the previous screenshot. Once Python has been updated in the path variables or system variables, the windows command line recognizes the python command and executes as shown here: 

During installation, the installer provides an option to set system variables, which we have seen in our installation steps. But in case you missed that out, you need not worry. You can manually set the system variables. Simply follow these steps:

  1. Just right-click on My Computer (older version of Windows PC) or Computer (win 7 onwards) and select Properties. Once you have selected the properties, you will get the following screenshot where you need to select Advanced system settings:
  1. After you have clicked on Advanced system settings, you will get System Properties. Click on the Environment Variables button. 
  2. After completing Step 2, a window will pop up. From the System variables pane, select Path and click on the Edit button.
  3. Your Python installation will look something like the following screenshot, where you need to right-click on the address bar and select the Copy address as text option:
  1. Add the Python installation folder path to the Path variable.
  2. Click on OK and then again on OK to close all the windows. Our system variable is set:

Setting environment variables in Linux

Linux comes with different types of shells and the Python directory path is usually /usr/local/bin/python:

  • csh shell: Open the terminal and enter setenv PATH "$PATH:/usr/local/bin/python" followed by pressing Enter
  • bash shell: On the terminal, enter export PATH="$PATH:/usr/local/bin/python" followed by pressing Enter
  • sh or ksh shell: Enter PATH="$PATH:/usr/local/bin/python" followed by pressing Enter

Setting environment variables in Mac OS (OS 10.9)

Here, simply you need to edit the launchd.conf file and add the path variable to the file:

$ sudo edit /etc/launchd.conf
setenv PYTHONPATH /Users/vesper/temp:/Users/vesper/misc
You have been reading a chapter from
Learn Python in 7 Days
Published in: May 2017
Publisher: Packt
ISBN-13: 9781787288386
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