Episode 1 Using the Interpreter

Similar documents
Introduction to Programming with Python 3, Ami Gates. Chapter 1: Creating a Programming Environment

Using Eclipse for Java. Using Eclipse for Java 1 / 1

Semester 2, 2018: Lab 1

Fundamentals: Expressions and Assignment

CSE 101 Introduction to Computers Development / Tutorial / Lab Environment Setup

Interactive Mode Python Pylab

General Guidelines: SAS Analyst

Code::Blocks Student Manual

AP Computer Science Principles Summer Assignment

Code::Blocks Student Manual

Getting Started with Python

Eclipse Setup. Opening Eclipse. Setting Up Eclipse for CS15

Science One CS : Getting Started

Writing and Running Programs

Anaconda Python Guide On Windows Github Pages

HOW TO USE CODE::BLOCKS IDE FOR COMPUTER PROGRAMMING LABORATORY SESSIONS

Eclipse Environment Setup

Installing and Running the Google App Engine On a Macintosh System

About the Tutorial. Audience. Prerequisites. Copyright & Disclaimer

CSCI 161: Introduction to Programming I Lab 1b: Hello, World (Eclipse, Java)

CST8152 Compilers Creating a C Language Console Project with Microsoft Visual Studio.Net 2010

CircuitPython with Jupyter Notebooks

Spyder Documentation. Release 3. Pierre Raybaut

Computational Programming with Python

Getting started with Python

Getting Started (1.8.7) 9/2/2009

At the shell prompt, enter idlde

2 Getting Started. Getting Started (v1.8.6) 3/5/2007

3 TUTORIAL. In This Chapter. Figure 1-0. Table 1-0. Listing 1-0.

Scientific Computing: Lecture 1

Ion Client User Manual

Start Active-HDL. Create a new workspace TUTORIAL #1 CREATING AND SIMULATING SIMPLE SCHEMATICS

Last Updated: FRC 2019 BETA

Variables are used to store data (numbers, letters, etc) in MATLAB. There are a few rules that must be followed when creating variables in MATLAB:

(Ca...

Zend Studio 3.0. Quick Start Guide

i2b2 Workbench Developer s Guide: Eclipse Neon & i2b2 Source Code

Java Program Structure and Eclipse. Overview. Eclipse Projects and Project Structure. COMP 210: Object-Oriented Programming Lecture Notes 1

RVDS 4.0 Introductory Tutorial

Table of Contents HOL-SDC-1422

TUTORIAL FOR IMPORTING OTTAWA FIRE HYDRANT PARKING VIOLATION DATA INTO MYSQL

Laboratory Exercise #0

Lesson 2: Preparation

COSC 490 Computational Topology

Getting Started with Python

Getting started with the Spyder IDE

Introduction to Computer Vision Laboratories

ME30_Lab1_18JUL18. August 29, ME 30 Lab 1 - Introduction to Anaconda, JupyterLab, and Python

1 Introduction to MARS

Installing Eclipse CDT and MinGW

Tutorial: GNU Radio Companion

The Basics of Visual Studio Code

Comodo Chromium Secure Software Version 36.1

DataPro Quick Start Guide

TUTORIAL FOR IMPORTING OTTAWA FIRE HYDRANT PARKING VIOLATION DATA INTO MYSQL

NetBeans Tutorial. For Introduction to Java Programming By Y. Daniel Liang. This tutorial applies to NetBeans 6, 7, or a higher version.

Getting Started with Python and the PyCharm IDE

Browser Configuration Reference

Lab #1: A Quick Introduction to the Eclipse IDE

Installation and Introduction to Jupyter & RStudio

Module 3: Working with C/C++

Navigating and Managing Files and Folders in Windows XP

Getting Started with Eclipse for Java

How to Download and Install R The R software can be downloaded from: Click on download R link.

FrontPage Help Center. Topic: FrontPage Basics

Comodo Dragon. User Guide Guide Version Software Version Comodo Security Solutions 525 Washington Blvd. Jersey City, NJ 07310

with TestComplete 12 Desktop, Web, and Mobile Testing Tutorials

Supplement H.1: JBuilder X Tutorial. For Introduction to Java Programming, 5E By Y. Daniel Liang

CS-Studio Display Builder

PCB Filter. Summary. Panel Access. Modified by Admin on Dec 12, PCB Inspector. Parent page: Panels

Episode 8 Matplotlib, SciPy, and Pandas. We will start with Matplotlib. The following code makes a sample plot.

Create an Accessible PDF (Adobe Acrobat Pro)

Supplement II.B(1): JBuilder X Tutorial. For Introduction to Java Programming By Y. Daniel Liang

PYTHON FOR MEDICAL PHYSICISTS. Radiation Oncology Medical Physics Cancer Care Services, Royal Brisbane & Women s Hospital

Comodo Dragon Software Version 24.0

Instituto Politécnico de Tomar. Python. Introduction. Ricardo Campos. Licenciatura ITM Técnicas Avançadas de Programação Abrantes, Portugal, 2018

Notepad++ The COMPSCI 101 Text Editor for Windows. What is a text editor? Install Python 3. Installing Notepad++

Code Autocomplete Manual

Excel 2016 Basics for Mac

OU EDUCATE TRAINING MANUAL

Programming with Python

The Road to CCSv4. Status Update

Test/Debug Guide. Reference Pages. Test/Debug Guide. Site Map Index

As CCS starts up, a splash screen similar to one shown below will appear.

IBM Rational Rhapsody Gateway Add On. User Manual

IBM Rational Rhapsody Gateway Add On. User Guide

WPS Workbench. user guide. To help guide you through using WPS Workbench to create, edit and run programs. Workbench user guide Version 3.

KNIME Python Integration Installation Guide. KNIME AG, Zurich, Switzerland Version 3.7 (last updated on )

Introduction to Python

LOCATION SPOOFING ON IOS WITHOUT A JAILBREAK

About the Tutorial. Audience. Prerequisites. Copyright & Disclaimer

A Quick Introduction to the Genesis Framework for WordPress. How to Install the Genesis Framework (and a Child Theme)

CST8152 Compilers Creating a C Language Console Project with Microsoft Visual Studio.Net 2005

LABORATORY OF DATA SCIENCE. Python & Spyder- recap. Data Science & Business Informatics Degree

Optimal Browser Settings Disable File Caching:

NAMI Affiliate Profile Center Contact Manual

ECE QNX Real-time Lab

TRAINING GUIDE. Web App End User Training

Laboratory 1: Eclipse and Karel the Robot

Quick Installation Guide: TC-Python

Transcription:

Episode 1 Using the Interpreter Anaconda We recommend, but do not require, the Anaconda distribution from Continuum Analytics (www.continuum.io). An overview is available at https://docs.continuum.io/anaconda. At the time the videos were produced, Anaconda distributed a frontend called Navigator. Through Navigator you can launch applications, manage your installation, and install new applications. Continuum provides documentation for Navigator at https://docs.continuum.io/anaconda/navigator. For an easy-to-use tool you can use from the command line, try conda. From Windows, run conda in the command prompt. From Mac OSX or Linux, open a terminal (Apps/Utilities on OSX). The conda cheat sheet (https://conda.io/docs/_downloads/conda-cheatsheet.pdf) is particularly helpful. Using conda you can update everything from a single package to the entire Anaconda distribution. You can also set up your environment to run both Python 2.7 and a version of Python 3. It is important to install Anaconda "Install for Me Only." You can find detailed installation instructions for your platform at https://docs.continuum.io/anaconda/install. It would be a good idea to open a command line and type conda install anaconda-clean so that you can completely uninstall the distribution should the need arise. Spyder We do strongly recommend the free, open-source Spyder Integrated Development Environment (IDE) for scientific and engineering programming, due to its integrated editor, interpreter console, and debugging tools. Spyder is included in Anaconda and other distributions, or it can be obtained from Github (https://github.com/spyder-ide/spyder). The official Spyder documentation is at https://pythonhosted.org/spyder; however, we recommend that beginners start with the tutorial included with Spyder. From the Help menu select Tutorial. The tutorial will open in the Object Inspector. You can follow along by scrolling and expanding the sections. Topics covered in this episode are described in more detail in the sections Shortcuts for useful functions and Plotting. This tutorial was prepared by Hans Fangohr of the University of Southampton in England. After you have gained some experience, you may wish to try other IDEs. An Internet search should show several possibilities, though not all of them are completely free.

Troubleshooting Several things can go wrong with your installation. Navigator may crash when you attempt to open it, especially on Macs. On a Mac you can start Spyder from the Terminal application by opening a window and typing spyder& This will enable you to continue to follow along while you try to resolve the Navigator problem. First try updating using conda conda update conda conda update anaconda If that doesn't work, uninstall with anaconda-clean yes Then re-download and reinstall. More troubleshooting tips are at https://docs.continuum.io/anaconda/troubleshooting You can also join the Anaconda Google group and request help. Also check whether your problem has been reported at https://github.com/continuumio/anaconda-issues/issues If you confirm you have a new issue, you can enter a bug report at the above site. Episode Summary We explored several features of the Spyder development environment. The default appearance of Spyder has three panes: the Editor, where you can type scripts; the Explorer, which has three tabs for Object, Variable, and File Explorers; and the ipython console. We used the menus to create a new file (File->new file) and to save it (File->Save as). We explored printing from the script in the editor pane of Spyder, and printing expressions directly in IPython. If you type print "Hello World" In the Editor pane, you must run it for the print to be carried out. You can also type commands directly into the ipython console. If you type an expression its value will be printed: In [1]: x=5 In [2]: y=7 In [3]:x+y Out [3]: 12

This is not the case for expressions typed alone on a line in the Editor pane. x=5 y-7 x+y Nothing will happen if we run the above lines of code. In the ipython console we can also use up-down arrow keys to scroll in our commands, and the right-left arrow keys to edit them. We learned to run scripts either with the green arrow icons or through the Run menu. Run/green arrow runs the entire script. Run selection or current line will run a highlighted portion of our script. We can create cells by enclosing chunks of code with lines consisting of #%% Run cell/green arrow with a box runs the cell. Run cell/green arrow, box, and red "line feed" arrow runs the cell and advances. A yellow triangle beside a line indicates a syntax error or potential problem. Spyder offers tab completion for names familiar to it. It can show a list of members of a package for your selection, and when you have chosen a function it can show you a list of its arguments. One of the handiest features of Spyder is the ability to indent and unindent blocks of code from the Edit menu. Click to highlight the text you wish to indent or unindent, then choose the appropriate option under Edit. We will later see why this is very useful. Another helpful option allows you to highlight several lines of code, then select "Add block comment." This will save you a lot of typing once you begin to write and debug your own programs. To remove the block comment, select it and choose "Remove block comment" from the Edit menu. We can see some of these these features in action by creating a simple plot Type matplotlib.pylab as plt First we see a yellow triangle, indicating plt is imported but not used. We ignore it since we know we will be using it. As we type x=plt. We see the editor show us our choices from the pylab package. we can select one or we can keep typing. We type x=plt.linsp to further narrow it down. That leads us to x=plt.linspace The editor then pops up a box with the arguments required by linspace. Finally we type inside the parentheses -1.*plt.pi,plt.pi, 100 for a final result of x=plt.linspace(-1.*plt.pi,plt.pi.,100) Finally we type y=plt.sin(x) plt.plot(x,y)

When we run this code, we see the plot appear embedded in the ipython console. We can right-click on the image to bring up a menu that allows us to save the plot. The Variable Explorer allows us to show the values of variables in our programs. It is particularly helpful for looking at a group of values (an array). We can change the number of decimal places printed by clicking "Format" and typing in an expression of the form %.3f for three decimal places. The Variable Explorer also includes icons for saving, refreshing, or importing data to our workspace. To clear all values in the workspace, type %reset at the ipython console. Now re-run your sine-plotting code and observe how the variables acquire values. We can right-click on the x values to see the full array. We can use the Format menu as described above to change the number of decimal places displayed for a floating-point number. If we ask for more decimal places than can be computed in the computer's hardware, we will find that the extra spaces will be filled with zeros. We can see this if we click on the variable representing pi and request %.64f. We know that pi has an infinite number of decimal places, but the approximation we see is limited to some finite number and the rest are represented by zeros. This clearly shows us the limitations of computing with finite representations of the mathematical real numbers. We can see another consequence of this by looking at the first 64 digits of the first entry in our y array; it should be exactly zero, but is not. We can save data through the Variable Explorer. The right sidebar of the Variable Explorer shows several icons. Hovering over each one shows what it does; we can refresh, refresh periodically, save, save as, import, and select options. As an example we can use the save as icon to save the variable y as sinedata.pydata; we can then clear our workspace with %reset and use the Variable Explorer import icon to reload it. From the File Explorer we can browse through icons on the menu bar to change to a different folder for our programs. Spyder's top text bar shows the working directory (or working folder) for our programs and other files. The File Explorer displays the contents of that folder. You can double-click on any file in the File Explorer to open it. If it ends in.py it will open in a new tab in the Editor pane. Otherwise you will be asked how you want to handle the file. We've now learned the basics of working with our chosen Integrated Development Environment. Several others are available for Python, some of which are free and others of which require payment at least for certain features. Popular alternatives to Spyder include PyCharm ( freemium i.e. you pay for certain features. www.jetbrains.com), Rodeo, which is similar to Spyder (http://blog.yhat.com/posts/introducing-rodeo.html), and the PyDev plug-in for Eclipse (www.pydev.org).

Further Resources Spyder contains its own built-in tutorial. It tends to expect some proficiency with Python and discusses concepts we haven t seen yet; or it may expect users to be beginners at Python but not at programming; however, it is worthwhile to go through at least part of the tutorial. To access it, start from the Help menu and select Spyder tutorial.