User Interfaces. getting arguments of the command line a command line interface to store points fitting points with polyfit of numpy

Size: px
Start display at page:

Download "User Interfaces. getting arguments of the command line a command line interface to store points fitting points with polyfit of numpy"

Transcription

1 User Interfaces 1 Command Line Interfaces getting arguments of the command line a command line interface to store points fitting points with polyfit of numpy 2 Encapsulation by Object Oriented Programming an interface to an anydbm object refactoring a script into a class 3 The Tk GUI Toolkit in Python Tkinter, Tk, and Tcl using the canvas widget MCS 507 Lecture 11 Mathematical, Statistical and Scientific Software Jan Verschelde, 20 September 2013 Scientific Software (MCS 507 L-11) user interfaces 20 September / 39

2 User Interfaces 1 Command Line Interfaces getting arguments of the command line a command line interface to store points fitting points with polyfit of numpy 2 Encapsulation by Object Oriented Programming an interface to an anydbm object refactoring a script into a class 3 The Tk GUI Toolkit in Python Tkinter, Tk, and Tcl using the canvas widget Scientific Software (MCS 507 L-11) user interfaces 20 September / 39

3 command line interfaces Many programs run without dialogue with user, as $ executable -options inputfile outputfile Command line arguments are useful for changing default values of parameters; running program in special mode, e.g.: python -O turns on basic optimization; without delaying for typed user input, we can use the time command of the operating system. Scientific Software (MCS 507 L-11) user interfaces 20 September / 39

4 print command line arguments To get the command line arguments into Python: import sys L = sys.argv print the list of arguments : print L print number of arguments :, len(l) for k in xrange(len(l)): print argument %d is %s % (k, L[k]) Scientific Software (MCS 507 L-11) user interfaces 20 September / 39

5 running show_cmdlinargs.py $ python show_cmdlinargs.py a 3.14 the list of arguments : [ show_cmdlinargs.py, a, 3.14 ] number of arguments : 3 argument 0 is show_cmdlinargs.py argument 1 is a argument 2 is 3.14 The arguments given at the command line are strings. Scientific Software (MCS 507 L-11) user interfaces 20 September / 39

6 executing Python scripts If the file hello_python.py contains #! /usr/bin/python print welcome to Python then we can run the script at the prompt $ as $./hello_python.py welcome to Python The script starts with the location of the interpreter. Do which python to find location of python. Eventually, do chmod +x hello_python.py. Possible to run script by clicking on its icon. Scientific Software (MCS 507 L-11) user interfaces 20 September / 39

7 User Interfaces 1 Command Line Interfaces getting arguments of the command line a command line interface to store points fitting points with polyfit of numpy 2 Encapsulation by Object Oriented Programming an interface to an anydbm object refactoring a script into a class 3 The Tk GUI Toolkit in Python Tkinter, Tk, and Tcl using the canvas widget Scientific Software (MCS 507 L-11) user interfaces 20 September / 39

8 storing data points Suppose we want to store points (x, y) permanently. Running our script storepoints.py as $./storepoints.py db=data -a 1,2 adding 1 2 $./storepoints.py db=data -v 1 value of 1 is 2 $./storepoints.py db=data -L (1,2) respectively adds (1,2), gets the value of 1, and lists all points stored in the anydbm file data. Scientific Software (MCS 507 L-11) user interfaces 20 September / 39

9 a top down design Starting at the top we apply stepwise refinement of the main program: 1 open the database, 2 decode the command line options, 3 for valid options, perform the action. The sequence of three steps in the main program is defined by the following subroutines: 1 open the database (anydbm object), 2 extract the option of a command line argument, 3 handle a valid option with 3 subroutines: 1 adding a point (x,y), 2 given x, get the corresponding y, 3 list all points. Scientific Software (MCS 507 L-11) user interfaces 20 September / 39

10 the main program def main(): Opens database and handles options. import sys cmdargs = sys.argv adb = open_database(cmdargs) if adb == None: print opening of database failed else: option = extract_option(cmdargs) if option == None: print no valid option found else: handle(adb, option) if name == " main ": main() Scientific Software (MCS 507 L-11) user interfaces 20 September / 39

11 opening the database def open_database(cmdlist): Extracts the database name from the list of command line arguments. If the database could be opened, then it is returned, otherwise None is returned. for item in cmdlist: items = item.split( = ) if len(items) == 2: try: adb = anydbm.open(items[1], c ) print opening, items[1], succeeded return adb except: print opening, items[1], failed return None return None Scientific Software (MCS 507 L-11) user interfaces 20 September / 39

12 extracting options def extract_option(cmdlist): Returns a tuple with the option letter and the data following the option. for k in xrange(len(cmdlist)): item = cmdlist[k] if item[0] == - : if item[1] == L : return ( L, None) try: return (item[1], cmdlist[k+1]) except: print no data with option, item[1] return None return None Scientific Software (MCS 507 L-11) user interfaces 20 September / 39

13 handling options def handle(adb, opt): Given in opt a tuple of option letter and argument, adds a point, returns a value, or prints an error message. if opt[0] == a : add_point(adb, opt[1]) elif opt[0] == v : value_of_point(adb, opt[1]) elif opt[0] == L : list_points(adb) else: print opt[0], is invalid option Scientific Software (MCS 507 L-11) user interfaces 20 September / 39

14 adding points def add_point(adb, inpstr): Adds the point in the string inpstr encoded as x,y. coords = inpstr.split(, ) (ptx, pty) = tuple(coords) print adding, ptx, pty adb[ptx] = pty Scientific Software (MCS 507 L-11) user interfaces 20 September / 39

15 getting values def value_of_point(adb, inpstr): Prints the value of the point with key stored in the string inpstr. if adb.has_key(inpstr): print value of, inpstr, is, adb[inpstr] else: print inpstr, has no value def list_points(adb): Shows the list of points stored in adb. for key in adb.keys(): print ( + key +, + adb[key] + ) Scientific Software (MCS 507 L-11) user interfaces 20 September / 39

16 User Interfaces 1 Command Line Interfaces getting arguments of the command line a command line interface to store points fitting points with polyfit of numpy 2 Encapsulation by Object Oriented Programming an interface to an anydbm object refactoring a script into a class 3 The Tk GUI Toolkit in Python Tkinter, Tk, and Tcl using the canvas widget Scientific Software (MCS 507 L-11) user interfaces 20 September / 39

17 using numpy.polyfit >>> import numpy as np >>> x = np.array([-1,0,1]) >>> y = np.array([2,0,3]) >>> p = np.polyfit(x,y,deg=2) >>> p array([ e+00, e-01, e-16]) >>> z = np.polyval(p,x) >>> z array([ e+00, e-16, e+00]) numpy.polyfit fits a set of points with a polynomial of a given degree, solving a least squares problem with a singular value decomposition. Scientific Software (MCS 507 L-11) user interfaces 20 September / 39

18 visualization with ipython Scientific Software (MCS 507 L-11) user interfaces 20 September / 39

19 session with ipython $ ipython --pylab In [1]: x = array([-1,0,1]); y = array([2,0,3]) In [2]: p = polyfit(x,y,deg=2) In [3]: r = arange(-1.5,1.5,0.01) In [4]: rp = polyval(p,r) In [5]: plot(x,y, rd ) Out[5]: [<matplotlib.lines.line2d at 0x1068f6110>] In [6]: plot(r,rp, b- ) Out[6]: [<matplotlib.lines.line2d at 0x d0>] Scientific Software (MCS 507 L-11) user interfaces 20 September / 39

20 User Interfaces 1 Command Line Interfaces getting arguments of the command line a command line interface to store points fitting points with polyfit of numpy 2 Encapsulation by Object Oriented Programming an interface to an anydbm object refactoring a script into a class 3 The Tk GUI Toolkit in Python Tkinter, Tk, and Tcl using the canvas widget Scientific Software (MCS 507 L-11) user interfaces 20 September / 39

21 Object Oriented Design Top down design works well for precisely defined programs but requirements in programs often change and bugs arise. The main object is a collection of tuples (x,y) stored in a database. To the user, the data (x,y) are just points. In an object oriented design, we have an object points. Encapsulation is also an interface. We will refactor the top down code into a class. Object oriented design works from the bottom up: we can test the operations on the points collection without a main program. Scientific Software (MCS 507 L-11) user interfaces 20 September / 39

22 defining a class The class defines an interface to an anydbm object: 1 Given a name of a database, the initialization creates a new or opens an existing database. 2 The string representation returns the list of points stored in the database. 3 The two other method are 1 add a point (x,y), 2 given x, return y. Encapsulation: the user of the class does not see anydbm. Scientific Software (MCS 507 L-11) user interfaces 20 September / 39

23 User Interfaces 1 Command Line Interfaces getting arguments of the command line a command line interface to store points fitting points with polyfit of numpy 2 Encapsulation by Object Oriented Programming an interface to an anydbm object refactoring a script into a class 3 The Tk GUI Toolkit in Python Tkinter, Tk, and Tcl using the canvas widget Scientific Software (MCS 507 L-11) user interfaces 20 September / 39

24 an interactive test In the Python shell: >>> from classpointsdb import * >>> p = Points("data") opening data succeeded >>> p.add_point("1,2") adding 1 2 >>> print str(p) (1,2) >>> p.value_of_point("1") 2 Scientific Software (MCS 507 L-11) user interfaces 20 September / 39

25 the constructor of the class import anydbm class Points(object): Encapsulation of an anydbm object to store a collection of coordinates of points in the plane. def init (self, name): Attempts to open the database with the name. try: self.adb = anydbm.open(name, c ) print opening, name, succeeded except: print opening, name, failed self.adb = None Scientific Software (MCS 507 L-11) user interfaces 20 September / 39

26 the string representation def str (self): Shows the list of stored points. keys = self.adb.keys() result = "" for k in keys: result += ( + k +, + self.adb[k] + ) return result Scientific Software (MCS 507 L-11) user interfaces 20 September / 39

27 adding a point def add_point(self, inpstr): Adds the point in the string inpstr encoded as x, y. coords = inpstr.split(, ) (ptx, pty) = tuple(coords) print adding, ptx, pty self.adb[ptx] = pty Scientific Software (MCS 507 L-11) user interfaces 20 September / 39

28 getting the value of a point def value_of_point(self, inpstr): Returns the value of the point with key stored in the string inpstr if self.adb.has_key(inpstr): return self.adb[inpstr] else: return None Scientific Software (MCS 507 L-11) user interfaces 20 September / 39

29 the test program def test(): Tests the methods of the Points class. pts = Points("data") pts.add_point("1,2") print str(pts) print "the value of 1 is", pts.value_of_point("1") if name == " main ": test() Scientific Software (MCS 507 L-11) user interfaces 20 September / 39

30 User Interfaces 1 Command Line Interfaces getting arguments of the command line a command line interface to store points fitting points with polyfit of numpy 2 Encapsulation by Object Oriented Programming an interface to an anydbm object refactoring a script into a class 3 The Tk GUI Toolkit in Python Tkinter, Tk, and Tcl using the canvas widget Scientific Software (MCS 507 L-11) user interfaces 20 September / 39

31 Tkinter, Tk, and Tcl The Tkinter (= Tk interface) library provides an object-oriented interface to the Tk GUI toolkit, the graphical interface development tool for Tcl, Tk = Tool Kit, Tcl = Tool Command Language. Benefit: platform independent GUI development. Scientific Software (MCS 507 L-11) user interfaces 20 September / 39

32 User Interfaces 1 Command Line Interfaces getting arguments of the command line a command line interface to store points fitting points with polyfit of numpy 2 Encapsulation by Object Oriented Programming an interface to an anydbm object refactoring a script into a class 3 The Tk GUI Toolkit in Python Tkinter, Tk, and Tcl using the canvas widget Scientific Software (MCS 507 L-11) user interfaces 20 September / 39

33 five points on canvas Scientific Software (MCS 507 L-11) user interfaces 20 September / 39

34 computing the coordinates from Tkinter import Tk, Canvas from math import cos, sin, pi D = 400 # number of pixels in rows/columns R = 0.8*D/2 # radius of the pentagon A = 2*pi/5 # dividing angle L = [(D/2, D/2-R), \ (D/2+R*cos(pi/2-A), D/2-R*sin(pi/2-A)), \ (D/2+R*cos(pi/2-2*A), D/2-R*sin(pi/2-2*A)), \ (D/2+R*cos(pi/2-3*A), D/2-R*sin(pi/2-3*A)), \ (D/2+R*cos(pi/2-4*A), D/2-R*sin(pi/2-4*A))] Note that the origin (0, 0) is at the topleft corner. Scientific Software (MCS 507 L-11) user interfaces 20 September / 39

35 a canvas widget We define a new window and title. The method pack() arranges the canvas in the window. WDW = Tk() WDW.title( five points ) C = Canvas(WDW, width=d, height=d, bg= white ) C.pack() for p in L: C.create_oval(p[0]-6, p[1]-6, p[0]+6, p[1]+6, \ width=1, outline= black, fill= SkyBlue2 ) The points are marked on canvas by blue disks. Scientific Software (MCS 507 L-11) user interfaces 20 September / 39

36 fitting the points Scientific Software (MCS 507 L-11) user interfaces 20 September / 39

37 applying polyfit import numpy as np A = np.array([x for (x, y) in L]) B = np.array([y for (x, y) in L]) QUARTIC = np.polyfit(a, B, 4) for i in xrange(400): j = np.polyval(quartic, i) C.create_oval(i-1, j-1, i+1, j+1, \ width=1, outline= red, fill= red ) WDW.mainloop() Scientific Software (MCS 507 L-11) user interfaces 20 September / 39

38 Summary + Exercises Command line arguments are passed as strings to a Python script. We make GUIs with TKinter (continued on Monday). Exercises: 1 Extend storepoints.py with an option -d x to delete points with given x value 2 Add an exception handler to the function add_point for when the comma is missing or the coordinates fail to convert to floats. 3 Modify the code for -v x of storepoints.py so that it returns the value of a quadratic fit in case the value for the given x is not stored. Scientific Software (MCS 507 L-11) user interfaces 20 September / 39

39 more exercises 4 Change the pentagon.py script so that it gets its points from an anydbm file made with storepoints.py. 5 Use the code in pentagon.py as a visualization module for storepoints.py. With the option -s a canvas window pops up displaying the stored points. The first project is due on Wednesday 2 October, at 9AM. Scientific Software (MCS 507 L-11) user interfaces 20 September / 39

User Interfaces. MCS 507 Lecture 11 Mathematical, Statistical and Scientific Software Jan Verschelde, 16 September Command Line Interfaces

User Interfaces. MCS 507 Lecture 11 Mathematical, Statistical and Scientific Software Jan Verschelde, 16 September Command Line Interfaces User 1 2 MCS 507 Lecture 11 Mathematical, Statistical and Scientific Software Jan Verschelde, 16 September 2011 User 1 2 command line interfaces Many programs run without dialogue with user, as $ executable

More information

Graphical User Interfaces

Graphical User Interfaces Graphical User Interfaces 1 User Interfaces GUIs in Python with Tkinter object oriented GUI programming 2 Mixing Colors specification of the GUI the widget Scale 3 Simulating a Bouncing Ball layout of

More information

Graphical User Interfaces

Graphical User Interfaces to visualize Graphical User Interfaces 1 2 to visualize MCS 507 Lecture 12 Mathematical, Statistical and Scientific Software Jan Verschelde, 19 September 2011 Graphical User Interfaces to visualize 1 2

More information

Root Finding Methods. sympy and Sage. MCS 507 Lecture 13 Mathematical, Statistical and Scientific Software Jan Verschelde, 21 September 2011

Root Finding Methods. sympy and Sage. MCS 507 Lecture 13 Mathematical, Statistical and Scientific Software Jan Verschelde, 21 September 2011 wrap Root Finding Methods 1 2 wrap MCS 507 Lecture 13 Mathematical, Statistical and Scientific Software Jan Verschelde, 21 September 2011 Root Finding Methods 1 wrap 2 wrap wrap octave-3.4.0:1> p = [1,0,2,-1]

More information

Outline. general information policies for the final exam

Outline. general information policies for the final exam Outline 1 final exam on Tuesday 5 May 2015, at 8AM, in BSB 337 general information policies for the final exam 2 some example questions strings, lists, dictionaries scope of variables in functions working

More information

List Comprehensions and Simulations

List Comprehensions and Simulations List Comprehensions and Simulations 1 List Comprehensions examples in the Python shell zipping, filtering, and reducing 2 Monte Carlo Simulations testing the normal distribution the Mean Time Between Failures

More information

Defining Functions. turning expressions into functions. writing a function definition defining and using modules

Defining Functions. turning expressions into functions. writing a function definition defining and using modules Defining Functions 1 Lambda Functions turning expressions into functions 2 Functions and Modules writing a function definition defining and using modules 3 Computing Series Developments exploring an example

More information

defining the class Parabola extending the Parabola class for visualization

defining the class Parabola extending the Parabola class for visualization Class Hierarchies 1 Points and Lines points in the plane extending the classpoint representing lines in the plane visualizing lines 2 Parabolas defining the class Parabola extending the Parabola class

More information

predator-prey simulations

predator-prey simulations predator-prey simulations 1 Hopping Frogs an object oriented model of a frog animating frogs with threads 2 Frogs on Canvas a GUI for hopping frogs stopping and restarting threads 3 Flying Birds an object

More information

Lists and Loops. defining lists lists as queues and stacks inserting and removing membership and ordering lists

Lists and Loops. defining lists lists as queues and stacks inserting and removing membership and ordering lists Lists and Loops 1 Lists in Python defining lists lists as queues and stacks inserting and removing membership and ordering lists 2 Loops in Python for and while loops the composite trapezoidal rule MCS

More information

callback, iterators, and generators

callback, iterators, and generators callback, iterators, and generators 1 Adding a Callback Function a function for Newton s method a function of the user to process results 2 A Newton Iterator defining a counter class refactoring the Newton

More information

turning expressions into functions symbolic substitution, series, and lambdify

turning expressions into functions symbolic substitution, series, and lambdify Defining Functions 1 Lambda Functions turning expressions into functions symbolic substitution, series, and lambdify 2 Functions and Modules writing a function definition defining and using modules where

More information

Tuples and Nested Lists

Tuples and Nested Lists stored in hash 1 2 stored in hash 3 and 4 MCS 507 Lecture 6 Mathematical, Statistical and Scientific Software Jan Verschelde, 2 September 2011 and stored in hash 1 2 stored in hash 3 4 stored in hash tuples

More information

processing data with a database

processing data with a database processing data with a database 1 MySQL and MySQLdb MySQL: an open source database running MySQL for database creation MySQLdb: an interface to MySQL for Python 2 CTA Tables in MySQL files in GTFS feed

More information

Branching and Enumeration

Branching and Enumeration Branching and Enumeration 1 Booleans and Branching computing logical expressions computing truth tables with Sage if, else, and elif 2 Timing Python Code try-except costs more than if-else 3 Recursive

More information

Outline. making colors with scale widgets entering parameter values using the variables in Scale. sliding canvas coordinates animating a random walk

Outline. making colors with scale widgets entering parameter values using the variables in Scale. sliding canvas coordinates animating a random walk Outline 1 The Widget Scale making colors with scale widgets entering parameter values using the variables in Scale 2 Building an Animation sliding canvas coordinates animating a random walk 3 Summary +

More information

Interactive Computing

Interactive Computing Interactive Computing 1 Input/Output and Complex Arithmetic interactive Python scripts complex arithmetic 2 Python Coding Style and pylint coding style static code checking with pylint 3 Programming with

More information

Introduction to Python

Introduction to Python Introduction to Python CB2-101 Introduction to Scientific Computing November 11 th, 2014 Emidio Capriotti http://biofold.org/emidio Division of Informatics Department of Pathology Python Python high-level

More information

Lists and Loops. browse Python docs and interactive help

Lists and Loops. browse Python docs and interactive help Lists and Loops 1 Help in Python browse Python docs and interactive help 2 Lists in Python defining lists lists as queues and stacks inserting and removing membership and ordering lists 3 Loops in Python

More information

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

PYTHON FOR MEDICAL PHYSICISTS. Radiation Oncology Medical Physics Cancer Care Services, Royal Brisbane & Women s Hospital PYTHON FOR MEDICAL PHYSICISTS Radiation Oncology Medical Physics Cancer Care Services, Royal Brisbane & Women s Hospital TUTORIAL 1: INTRODUCTION Thursday 1 st October, 2015 AGENDA 1. Reference list 2.

More information

Numerical Integration

Numerical Integration Numerical Integration 1 Functions using Functions functions as arguments of other functions the one-line if-else statement functions returning multiple values 2 Constructing Integration Rules with sympy

More information

Random Walks & Cellular Automata

Random Walks & Cellular Automata Random Walks & Cellular Automata 1 Particle Movements basic version of the simulation vectorized implementation 2 Cellular Automata pictures of matrices an animation of matrix plots the game of life of

More information

Review for Second Midterm Exam

Review for Second Midterm Exam Review for Second Midterm Exam 1 Policies & Material 2 Questions modular design working with files object-oriented programming testing, exceptions, complexity GUI design and implementation MCS 260 Lecture

More information

Introduction to Python and NumPy I

Introduction to Python and NumPy I Introduction to Python and NumPy I This tutorial is continued in part two: Introduction to Python and NumPy II Table of contents Overview Launching Canopy Getting started in Python Getting help Python

More information

Teaching London Computing

Teaching London Computing Teaching London Computing A Level Computer Science Programming GUI in Python William Marsh School of Electronic Engineering and Computer Science Queen Mary University of London How the Session Works Outline

More information

Programming Training. This Week: Tkinter for GUI Interfaces. Some examples

Programming Training. This Week: Tkinter for GUI Interfaces. Some examples Programming Training This Week: Tkinter for GUI Interfaces Some examples Tkinter Overview Set of widgets designed by John K. Ousterhout, 1987 Tkinter == Tool Kit Interface Mean to be driven by Tcl (Toolkit

More information

CMPSCI 119 Fall 2018 Wednesday, November 14, 2018 Midterm #2 Solution Key Professor William T. Verts

CMPSCI 119 Fall 2018 Wednesday, November 14, 2018 Midterm #2 Solution Key Professor William T. Verts CMPSCI 119 Fall 2018 Wednesday, November 14, 2018 Midterm #2 Solution Key Professor William T. Verts 25 Points What is the value of each expression below? Answer any 25; answer more for extra credit.

More information

1 Check it out! : Fundamentals of Programming and Computer Science, Fall Homework 3 Programming: Image Processing

1 Check it out! : Fundamentals of Programming and Computer Science, Fall Homework 3 Programming: Image Processing 15-112 Homework 3 Page 1 of 5 15-112: Fundamentals of Programming and Computer Science, Fall 2017 Homework 3 Programming: Image Processing Due: Tuesday, September 26, 2017 by 22:00 This programming homework

More information

CHAPTER 2: Introduction to Python COMPUTER PROGRAMMING SKILLS

CHAPTER 2: Introduction to Python COMPUTER PROGRAMMING SKILLS CHAPTER 2: Introduction to Python COMPUTER PROGRAMMING SKILLS 1439-1440 1 Outline 1. Introduction 2. Why Python? 3. Compiler and Interpreter 4. The first program 5. Comments and Docstrings 6. Python Indentations

More information

Python Programming, bridging course 2011

Python Programming, bridging course 2011 Python Programming, bridging course 2011 About the course Few lectures Focus on programming practice Slides on the homepage No course book. Using online resources instead. Online Python resources http://www.python.org/

More information

Introduction to MATLAB

Introduction to MATLAB Outlines September 9, 2004 Outlines Part I: Review of Previous Lecture Part II: Part III: Writing MATLAB Functions Review of Previous Lecture Outlines Part I: Review of Previous Lecture Part II: Part III:

More information

CSC 110 Final Exam. ID checked

CSC 110 Final Exam. ID checked ID checked CSC 110 Final Exam Name: Date: 1. Write a Python program that asks the user for a positive integer n and prints out n evenly spaced values between 0 and 10. The values should be printed with

More information

ENGR/CS 101 CS Session Lecture 15

ENGR/CS 101 CS Session Lecture 15 ENGR/CS 101 CS Session Lecture 15 Log into Windows/ACENET (reboot if in Linux) Use web browser to go to session webpage http://csserver.evansville.edu/~hwang/f14-courses/cs101.html Right-click on lecture15.py

More information

[CHAPTER] 1 INTRODUCTION 1

[CHAPTER] 1 INTRODUCTION 1 FM_TOC C7817 47493 1/28/11 9:29 AM Page iii Table of Contents [CHAPTER] 1 INTRODUCTION 1 1.1 Two Fundamental Ideas of Computer Science: Algorithms and Information Processing...2 1.1.1 Algorithms...2 1.1.2

More information

Multithreaded Servers

Multithreaded Servers Multithreaded Servers 1 Serving Multiple Clients avoid to block clients with waiting using sockets and threads 2 Waiting for Data from 3 Clients running a simple multithreaded server code for client and

More information

Midterm I Practice Problems

Midterm I Practice Problems 15-112 Midterm I Practice Problems Name: Section: andrewid: This PRACTICE midterm is not meant to be a perfect representation of the upcoming midterm! You are responsible for knowing all material covered

More information

Ch.2: Loops and lists

Ch.2: Loops and lists Ch.2: Loops and lists Joakim Sundnes 1,2 Hans Petter Langtangen 1,2 Simula Research Laboratory 1 University of Oslo, Dept. of Informatics 2 Aug 29, 2018 Plan for 28 August Short quiz on topics from last

More information

Outline. overview & concepts files and processes in UNIX the platform and os modules. importing the turtle module drawing a spiral colors with turtle

Outline. overview & concepts files and processes in UNIX the platform and os modules. importing the turtle module drawing a spiral colors with turtle Outline 1 Operating Systems overview & concepts files and processes in UNIX the platform and os modules 2 Turtle Graphics importing the turtle module drawing a spiral colors with turtle 3 Summary + Assignments

More information

Python Programming Exercises 1

Python Programming Exercises 1 Python Programming Exercises 1 Notes: throughout these exercises >>> preceeds code that should be typed directly into the Python interpreter. To get the most out of these exercises, don t just follow them

More information

operator overloading algorithmic differentiation the class DifferentialNumber operator overloading

operator overloading algorithmic differentiation the class DifferentialNumber operator overloading operator overloading 1 Computing with Differential Numbers algorithmic differentiation the class DifferentialNumber operator overloading 2 Computing with Double Doubles the class DoubleDouble defining

More information

Basic Beginners Introduction to plotting in Python

Basic Beginners Introduction to plotting in Python Basic Beginners Introduction to plotting in Python Sarah Blyth July 23, 2009 1 Introduction Welcome to a very short introduction on getting started with plotting in Python! I would highly recommend that

More information

tutorial : modeling synaptic plasticity

tutorial : modeling synaptic plasticity tutorial : modeling synaptic plasticity Computational Neuroscience by the Mediterranean Winter School, Jan 20th, 2016 Michael Graupner Université Paris Descartes CNRS UMR 8118, Paris, France michael.graupner@parisdescartes.fr

More information

Datenanalyse (PHY231) Herbstsemester 2017

Datenanalyse (PHY231) Herbstsemester 2017 Datenanalyse (PHY231) Herbstsemester 2017 A short pylab repetition 22/09/2017 An important part of the exercises for this course involves programming in python / pylab. We assume that you have completed

More information

Tcl/Tk for XSPECT a Michael Flynn

Tcl/Tk for XSPECT a Michael Flynn Tcl/Tk for XSPECT a Michael Flynn Tcl: Tcl (i.e. Tool Command Language) is an open source scripting language similar to other modern script languages such as Perl or Python. It is substantially more powerful

More information

UNIVERSITETET I OSLO

UNIVERSITETET I OSLO UNIVERSITETET I OSLO Det matematisk-naturvitenskapelige fakultet Examination in: INF1100 Introduction to programming with scientific applications Day of examination: Monday, October 5, 2015 Examination

More information

making connections general transit feed specification stop names and stop times storing the connections in a dictionary

making connections general transit feed specification stop names and stop times storing the connections in a dictionary making connections 1 CTA Tables general transit feed specification stop names and stop times storing the connections in a dictionary 2 CTA Schedules finding connections between stops sparse matrices in

More information

Web Clients and Crawlers

Web Clients and Crawlers Web Clients and Crawlers 1 Web Clients alternatives to web browsers opening a web page and copying its content 2 Scanning Files looking for strings between double quotes parsing URLs for the server location

More information

CAS London CPD Day February 16

CAS London CPD Day February 16 Practical Sheet: GUI Programming This sheet is a set of exercises for introducing GUI programming in Python using Tkinter, assuming knowledge of basic Python programming. All materials are at http://www.eecs.qmul.ac.uk/~william/cas-london-2016.html

More information

Functions with Parameters and Return Values

Functions with Parameters and Return Values CS101, Spring 2015 Functions with Parameters and Return Values Lecture #4 Last week we covered Objects and Types Variables Methods Tuples Roadmap Last week we covered Objects and Types Variables Methods

More information

Introductory Linux Course. Python II. Martin Dahlö UPPMAX. Author: Nina Fischer. Dept. for Cell and Molecular Biology, Uppsala University

Introductory Linux Course. Python II. Martin Dahlö UPPMAX. Author: Nina Fischer. Dept. for Cell and Molecular Biology, Uppsala University Introductory Linux Course Python II Martin Dahlö UPPMAX Author: Nina Fischer Dept. for Cell and Molecular Biology, Uppsala University August, 2018 Outline Short recap Functions Similarity of sequences

More information

python 01 September 16, 2016

python 01 September 16, 2016 python 01 September 16, 2016 1 Introduction to Python adapted from Steve Phelps lectures - (http://sphelps.net) 2 Python is interpreted Python is an interpreted language (Java and C are not). In [1]: 7

More information

Course Outline - COMP150. Lectures and Labs

Course Outline - COMP150. Lectures and Labs Course Outline - COMP150 Lectures and Labs 1 The way of the program 1.1 The Python programming language 1.2 What is a program? 1.3 What is debugging? 1.4 Experimental debugging 1.5 Formal and natural languages

More information

Test #2 October 8, 2015

Test #2 October 8, 2015 CPSC 1040 Name: Test #2 October 8, 2015 Closed notes, closed laptop, calculators OK. Please use a pencil. 100 points, 5 point bonus. Maximum score 105. Weight of each section in parentheses. If you need

More information

Introduction to Scientific Computing with Python, part two.

Introduction to Scientific Computing with Python, part two. Introduction to Scientific Computing with Python, part two. M. Emmett Department of Mathematics University of North Carolina at Chapel Hill June 20 2012 The Zen of Python zen of python... fire up python

More information

Table of Contents EVALUATION COPY

Table of Contents EVALUATION COPY Table of Contents Introduction... 1-2 A Brief History of Python... 1-3 Python Versions... 1-4 Installing Python... 1-5 Environment Variables... 1-6 Executing Python from the Command Line... 1-7 IDLE...

More information

Introductory Linux Course. Python II. Pavlin Mitev UPPMAX. Author: Nina Fischer Dept. for Cell and Molecular Biology, Uppsala University

Introductory Linux Course. Python II. Pavlin Mitev UPPMAX. Author: Nina Fischer Dept. for Cell and Molecular Biology, Uppsala University Introductory Linux Course Python II Pavlin Mitev UPPMAX Author: Nina Fischer Dept. for Cell and Molecular Biology, Uppsala University August, 2017 Outline Short recap Functions Similarity of sequences

More information

Python Tutorial. CS/CME/BioE/Biophys/BMI 279 Oct. 17, 2017 Rishi Bedi

Python Tutorial. CS/CME/BioE/Biophys/BMI 279 Oct. 17, 2017 Rishi Bedi Python Tutorial CS/CME/BioE/Biophys/BMI 279 Oct. 17, 2017 Rishi Bedi 1 Python2 vs Python3 Python syntax Data structures Functions Debugging Classes The NumPy Library Outline 2 Many examples adapted from

More information

Senthil Kumaran S

Senthil Kumaran S Senthil Kumaran S http://www.stylesen.org/ Agenda History Basics Control Flow Functions Modules History What is Python? Python is a general purpose, object-oriented, high level, interpreted language Created

More information

NumPy quick reference

NumPy quick reference John W. Shipman 2016-05-30 12:28 Abstract A guide to the more common functions of NumPy, a numerical computation module for the Python programming language. This publication is available in Web form1 and

More information

Random Walks & Cellular Automata

Random Walks & Cellular Automata Random Walks & Cellular Automata 1 Particle Movements basic version of the simulation vectorized implementation 2 Cellular Automata pictures of matrices an animation of matrix plots the game of life of

More information

Python review. 1 Python basics. References. CS 234 Naomi Nishimura

Python review. 1 Python basics. References. CS 234 Naomi Nishimura Python review CS 234 Naomi Nishimura The sections below indicate Python material, the degree to which it will be used in the course, and various resources you can use to review the material. You are not

More information

CS Advanced Unix Tools & Scripting

CS Advanced Unix Tools & Scripting & Scripting Spring 2011 Hussam Abu-Libdeh slides by David Slater March 4, 2011 Hussam Abu-Libdeh slides by David Slater & Scripting Python An open source programming language conceived in the late 1980s.

More information

Mid Unit Review. Of the four learning outcomes for this unit, we have covered the first two. 1.1 LO1 2.1 LO2 LO2

Mid Unit Review. Of the four learning outcomes for this unit, we have covered the first two. 1.1 LO1 2.1 LO2 LO2 Lecture 8 Mid Unit Review Of the four learning outcomes for this unit, we have covered the first two. LO Learning outcome (LO) AC Assessment criteria for pass The learner can: LO1 Understand the principles

More information

Interactive Mode Python Pylab

Interactive Mode Python Pylab Short Python Intro Gerald Schuller, Nov. 2016 Python can be very similar to Matlab, very easy to learn if you already know Matlab, it is Open Source (unlike Matlab), it is easy to install, and unlike Matlab

More information

PYTHON FOR KIDS A Pl ayfu l I ntrodu ctio n to Prog r am m i ng J a s o n R. B r i g g s

PYTHON FOR KIDS A Pl ayfu l I ntrodu ctio n to Prog r am m i ng J a s o n R. B r i g g s PYTHON FO R K I D S A P l ay f u l I n t r o d u c t i o n to P r o g r a m m i n g Jason R. Briggs Index Symbols and Numbers + (addition operator), 17 \ (backslash) to separate lines of code, 235 in strings,

More information

UNIVERSITETET I OSLO

UNIVERSITETET I OSLO (Continued on page 2.) UNIVERSITETET I OSLO Det matematisk-naturvitenskapelige fakultet Examination in: INF1100 Introduction to programming with scientific applications Day of examination: Thursday, October

More information

Review. Input, Processing and Output. Review. Review. Designing a Program. Typical Software Development cycle. Bonita Sharif

Review. Input, Processing and Output. Review. Review. Designing a Program. Typical Software Development cycle. Bonita Sharif Input, Processing and Output Bonita Sharif 1 Review A program is a set of instructions a computer follows to perform a task The CPU is responsible for running and executing programs A set of instructions

More information

1. Complete these exercises to practice creating user functions in small sketches.

1. Complete these exercises to practice creating user functions in small sketches. Lab 6 Due: Fri, Nov 4, 9 AM Consult the Standard Lab Instructions on LEARN for explanations of Lab Days ( D1, D2, D3 ), the Processing Language and IDE, and Saving and Submitting. Rules: Do not use the

More information

Introduction to Computer Programming in Python Dr. William C. Bulko. Data Types

Introduction to Computer Programming in Python Dr. William C. Bulko. Data Types Introduction to Computer Programming in Python Dr William C Bulko Data Types 2017 What is a data type? A data type is the kind of value represented by a constant or stored by a variable So far, you have

More information

Easy Graphical User Interfaces

Easy Graphical User Interfaces Easy Graphical User Interfaces with breezypythongui Types of User Interfaces GUI (graphical user interface) TUI (terminal-based user interface) UI Inputs Outputs Computation Terminal-Based User Interface

More information

processing data from the web

processing data from the web processing data from the web 1 CTA Tables general transit feed specification stop identification and name finding trips for a given stop 2 CTA Tables in MySQL files in GTFS feed are tables in database

More information

Introduction to Scientific Python, CME 193 Jan. 9, web.stanford.edu/~ermartin/teaching/cme193-winter15

Introduction to Scientific Python, CME 193 Jan. 9, web.stanford.edu/~ermartin/teaching/cme193-winter15 1 LECTURE 1: INTRO Introduction to Scientific Python, CME 193 Jan. 9, 2014 web.stanford.edu/~ermartin/teaching/cme193-winter15 Eileen Martin Some slides are from Sven Schmit s Fall 14 slides 2 Course Details

More information

UNIVERSITETET I OSLO

UNIVERSITETET I OSLO (Continued on page 2.) UNIVERSITETET I OSLO Det matematisk-naturvitenskapelige fakultet Examination in: INF1100 Introduction to programming with scientific applications Day of examination: Friday, December

More information

Downloaded from Chapter 2. Functions

Downloaded from   Chapter 2. Functions Chapter 2 Functions After studying this lesson, students will be able to: Understand and apply the concept of module programming Write functions Identify and invoke appropriate predefined functions Create

More information

CME 193: Introduction to Scientific Python Lecture 1: Introduction

CME 193: Introduction to Scientific Python Lecture 1: Introduction CME 193: Introduction to Scientific Python Lecture 1: Introduction Nolan Skochdopole stanford.edu/class/cme193 1: Introduction 1-1 Contents Administration Introduction Basics Variables Control statements

More information

CS 2316 Individual Homework 5 Joint Probability Out of 100 points

CS 2316 Individual Homework 5 Joint Probability Out of 100 points CS 2316 Individual Homework 5 Joint Probability Out of 100 points Files to submit: 1. HW5.py This is an INDIVIDUAL Assignment: Collaboration at a reasonable level will not result in substantially similar

More information

Introduction to Python. Genome 559: Introduction to Statistical and Computational Genomics Prof. James H. Thomas

Introduction to Python. Genome 559: Introduction to Statistical and Computational Genomics Prof. James H. Thomas Introduction to Python Genome 559: Introduction to Statistical and Computational Genomics Prof. James H. Thomas If you have your own PC, download and install a syntax-highlighting text editor and Python

More information

UNIT 10A Visualizing Data: Graphics in Python. Drawing using Python. We will be using Python's interface to Tcl/Tk, a cross-plaoorm graphics library.

UNIT 10A Visualizing Data: Graphics in Python. Drawing using Python. We will be using Python's interface to Tcl/Tk, a cross-plaoorm graphics library. UNIT 10A Visualizing Data: Graphics in Python 1 Drawing using Python We will be using Python's interface to Tcl/Tk, a cross-plaoorm graphics library. To use this, you should be logged in directly into

More information

Introduction to Problem Solving and Programming in Python.

Introduction to Problem Solving and Programming in Python. Introduction to Problem Solving and Programming in Python http://cis-linux1.temple.edu/~tuf80213/courses/temple/cis1051/ Overview Types of errors Testing methods Debugging in Python 2 Errors An error in

More information

The Use of Python Scripts in TAU. Thomas Gerhold. Folie 1 > TAU -Python scripting capability. 22/23t September 20055

The Use of Python Scripts in TAU. Thomas Gerhold. Folie 1 > TAU -Python scripting capability. 22/23t September 20055 The Use of Python Scripts in TAU Thomas Gerhold Folie 1 > TAU -Python scripting capability 22/23t September 20055 Overview Background Idea Perspectives Usage of python scripts Scripting examples & capabilities

More information

CS Programming Languages: Python

CS Programming Languages: Python CS 3101-1 - Programming Languages: Python Lecture 5: Exceptions / Daniel Bauer (bauer@cs.columbia.edu) October 08 2014 Daniel Bauer CS3101-1 Python - 05 - Exceptions / 1/35 Contents Exceptions Daniel Bauer

More information

Floating-Point Arithmetic

Floating-Point Arithmetic Floating-Point Arithmetic 1 Numerical Analysis a definition sources of error 2 Floating-Point Numbers floating-point representation of a real number machine precision 3 Floating-Point Arithmetic adding

More information

Sunpy Python for Solar Physics Juan Carlos Martínez Oliveros

Sunpy Python for Solar Physics Juan Carlos Martínez Oliveros Sunpy Python for Solar Physics Juan Carlos Martínez Oliveros In the beginning (ENIAC) Evolution Evolution Evolution Introduction The SunPy project is an effort to create an opensource software library

More information

Lecture 3 - Overview. More about functions Operators Very briefly about naming conventions Graphical user interfaces (GUIs)

Lecture 3 - Overview. More about functions Operators Very briefly about naming conventions Graphical user interfaces (GUIs) Lecture 3 - Overview More about functions Operators Very briefly about naming conventions Graphical user interfaces (GUIs) Function parameters Passed by reference, but the standard implication that the

More information

ERTH3021 Exploration and Mining Geophysics

ERTH3021 Exploration and Mining Geophysics ERTH3021 Exploration and Mining Geophysics Practical 1: Introduction to Scientific Programming using Python Purposes To introduce simple programming skills using the popular Python language. To provide

More information

Research Computing with Python, Lecture 1

Research Computing with Python, Lecture 1 Research Computing with Python, Lecture 1 Ramses van Zon SciNet HPC Consortium November 4, 2014 Ramses van Zon (SciNet HPC Consortium)Research Computing with Python, Lecture 1 November 4, 2014 1 / 35 Introduction

More information

CMPSCI 119 Spring 2015 Final Exam Friday, May 1, 2015 Solution Key

CMPSCI 119 Spring 2015 Final Exam Friday, May 1, 2015 Solution Key CMPSCI 119 Spring 2015 Final Exam Friday, May 1, 2015 Solution Key 25 Points Answer any 25 questions. Answer more for extra credit. Be careful about which variables and constants are integers, which

More information

Scientific Computing: Lecture 1

Scientific Computing: Lecture 1 Scientific Computing: Lecture 1 Introduction to course, syllabus, software Getting started Enthought Canopy, TextWrangler editor, python environment, ipython, unix shell Data structures in Python Integers,

More information

User-Defined Function

User-Defined Function ENGR 102-213 (Socolofsky) Week 11 Python scripts In the lecture this week, we are continuing to learn powerful things that can be done with userdefined functions. In several of the examples, we consider

More information

First name (printed): a. DO NOT OPEN YOUR EXAM BOOKLET UNTIL YOU HAVE BEEN TOLD TO BEGIN.

First name (printed): a. DO NOT OPEN YOUR EXAM BOOKLET UNTIL YOU HAVE BEEN TOLD TO BEGIN. CSE 231 F 13 Exam #1 Last name (printed): First name (printed): Form 1 X Directions: a. DO NOT OPEN YOUR EXAM BOOKLET UNTIL YOU HAVE BEEN TOLD TO BEGIN. b. This exam booklet contains 25 questions, each

More information

Web Interfaces. the web server Apache processing forms with Python scripts Python code to write HTML

Web Interfaces. the web server Apache processing forms with Python scripts Python code to write HTML Web Interfaces 1 Python Scripts in Browsers the web server Apache processing forms with Python scripts Python code to write HTML 2 Web Interfaces for the Determinant dynamic interactive forms passing data

More information

S206E Lecture 19, 5/24/2016, Python an overview

S206E Lecture 19, 5/24/2016, Python an overview S206E057 Spring 2016 Copyright 2016, Chiu-Shui Chan. All Rights Reserved. Global and local variables: differences between the two Global variable is usually declared at the start of the program, their

More information

Level 3 Computing Year 2 Lecturer: Phil Smith

Level 3 Computing Year 2 Lecturer: Phil Smith Level 3 Computing Year 2 Lecturer: Phil Smith We looked at: Debugging Previously BTEC Level 3 Year 2 Unit 16 Procedural programming Now Now we will look at: GUI applications. BTEC Level 3 Year 2 Unit 16

More information

Programming to Python

Programming to Python Programming to Python Sept., 5 th Slides by M. Stepp, M. Goldstein, M. DiRamio, and S. Shah Compiling and interpreting Many languages require you to compile (translate) your program into a form that the

More information

+. n is the function parameter and the function returns the sum.

+. n is the function parameter and the function returns the sum. CS/INFO 1305 Programming Exercise 2 Due Wednesday, July 22, at 10pm Submit either Level 1 or Level 2. For Level 2, problem 2.3 is required; complete ONE of 2.1 and 2.2. 1 Level 1 1. During the previous

More information

Table of Contents. Preface... xxi

Table of Contents. Preface... xxi Table of Contents Preface... xxi Chapter 1: Introduction to Python... 1 Python... 2 Features of Python... 3 Execution of a Python Program... 7 Viewing the Byte Code... 9 Flavors of Python... 10 Python

More information

61A Lecture 3. Friday, September 5

61A Lecture 3. Friday, September 5 61A Lecture 3 Friday, September 5 Announcements There's plenty of room in live lecture if you want to come (but videos are still better) Please don't make noise outside of the previous lecture! Homework

More information

ENGR (Socolofsky) Week 07 Python scripts

ENGR (Socolofsky) Week 07 Python scripts ENGR 102-213 (Socolofsky) Week 07 Python scripts A couple programming examples for this week are embedded in the lecture notes for Week 7. We repeat these here as brief examples of typical array-like operations

More information

Running Cython. overview hello world with Cython. experimental setup adding type declarations cdef functions & calling external functions

Running Cython. overview hello world with Cython. experimental setup adding type declarations cdef functions & calling external functions Running Cython 1 Getting Started with Cython overview hello world with Cython 2 Numerical Integration experimental setup adding type declarations cdef functions & calling external functions 3 Using Cython

More information

Introduction to Python. Prof. Steven Ludtke

Introduction to Python. Prof. Steven Ludtke Introduction to Python Prof. Steven Ludtke sludtke@bcm.edu 1 8512 documented lanuages (vs. 2376) Four of the first modern languages (50s): FORTRAN (FORmula ( TRANslator LISP (LISt ( Processor ALGOL COBOL

More information