Tips. Iteration On a list: o group = ["Paul","Duncan","Jessica"] for person in group: print(group) On a dictionary: o stock = {'eggs':15, 'milk':3, 'sugar':28}

Slides:



Advertisements
Similar presentations
COP 3530 JDK Environment Variables. COP 3530 JDK Environment Variables Environment Variables Environment variables are a set of dynamic values that can.
Advertisements

Introduction to Python. Python is a high-level programming language Open source and community driven “Batteries Included” – a standard distribution includes.
Computer Science 111 Fundamentals of Programming I Files.
Geography 465 Modules and Functions Writing Custom Functions.
E.1 Eclipse. e.2 Installing Eclipse Download the eclipse.installation.exe from the course web site to your computer and execute it. Keep the destination.
2006 GIS Jam: ArcGIS Python Scripting
Agenda Control Flow Statements Purpose test statement if / elif / else Statements for loops while vs. until statements case statement break vs. continue.
Introduction to Python John Reiser May 5 th, 2010.
Introduction to Python Basics of the Language. Install Python Find the most recent distribution for your computer at:
Chapter 14 Files and Exceptions II. "The Practice of Computing Using Python", Punch & Enbody, Copyright © 2013 Pearson Education, Inc. What we already.
Builtins, namespaces, functions. There are objects that are predefined in Python Python built-ins When you use something without defining it, it means.
The Python interpreter CSE 140 University of Washington Michael Ernst.
Sorting and Modules. Sorting Lists have a sort method >>> L1 = ["this", "is", "a", "list", "of", "words"] >>> print L1 ['this', 'is', 'a', 'list', 'of',
Functions Reading/writing files Catching exceptions
ATG Environment Setup In this session you will learn – Setting Up ATG environment – Creating new ATG application – Configuring Data Source – Configuring.
2. Recording a Macro. Macro Recording Select Record Macro from the Macro file menu and the dialog box opposite will appear Your macro will require a name.
Python Lists and Such CS 4320, SPRING List Functions len(s) is the length of list s s + t is the concatenation of lists s and t s.append(x) adds.
JCreator Tonga Institute of Higher Education. Programming with the command line and notepad is difficult. DOS disadvantages  User Interface (UI) is not.
By James Braunsberg. What are Modules? Modules are files containing Python definitions and statements (ex. name.py) A module’s definitions can be imported.
Module 6: Geoprocessing Scripts. Processing loops and decisions.
Getting Started with Python: Constructs and Pitfalls Sean Deitz Advanced Programming Seminar September 13, 2013.
BEGINNING MULTIPLICATION BASIC FACTS Multiplication is REPEATED ADDITION. It is a shortcut to skip counting. The first number in the problem tells.
Overview Intro to functions What are functions? Why use functions? Defining functions Calling functions Documenting functions Top-down design Variable.
Ch. 10 For Statement Dr. Bernard Chen Ph.D. University of Central Arkansas Spring 2012.
File I/O Michael Ernst UW CSE 140 Winter File Input and Output As a programmer, when would one use a file? As a programmer, what does one do with.
1 Getting Started with C++. 2 Objective You will be able to create, compile, and run a very simple C++ program on Windows, using Visual Studio 2008.
Illustration of a Visual Basic Program Running an Ada Program 1 by Richard Conn 11 September 1999.
File I/O Ruth Anderson UW CSE 160 Spring File Input and Output As a programmer, when would one use a file? As a programmer, what does one do with.
Dictionaries.   Review on for loops – nested for loops  Dictionaries (p.79 Learning Python)  Sys Module for system arguments  Reverse complementing.
IDLE An IDE for Python bundled with the program release Click on IDLE (Python GUI) in the Start menu under the Python program group  Get the IDLE Python.
Guide to Programming with Python Chapter Seven Files and Exceptions: The Trivia Challenge Game.
Shell Interface Shell Interface Functions Data. Graphical Interface Graphical Interface Command-line Interface Command-line Interface Experiments Private.
Trinity College Dublin, The University of Dublin GE3M25: Computer Programming for Biologists Python Karsten Hokamp, PhD Genetics TCD, 03/11/2015.
CS2021 Python Programming Week 3 Systems Programming PP-Part II.
Win32 Programming Lesson 19: Introduction to DLLs.
Exploring Spyder: An IDE for scientific computing
Xi Wang Yang Zhang. 1. Easy to learn 2. Clean and readable codes 3. A lot of useful packages, especially for web scraping and text mining 4. Growing popularity.
Learn R Toolkit D Kelly O'DayInstall & SetupMod 1 - Setup: 1 Module 1 Installing & Setting Up R Do See & HearRead Learn PowerPoint must be in View Show.
File I/O Ruth Anderson UW CSE 140 Winter File Input and Output As a programmer, when would one use a file? As a programmer, what does one do with.
CIT 590 Intro to Programming Files etc. Agenda Files Try catch except A module to read html off a remote website (only works sometimes)
LECTURE 2 Python Basics. MODULES So, we just put together our first real Python program. Let’s say we store this program in a file called fib.py. We have.
Creating and Using Modules Sec 9-6 Web Design. Objectives The student will: Know how to create and save a module in Python Know how to include your modules.
Intelligent Data Systems Lab. Department of Computer Science & Engineering Python Installation guide 컴퓨터의 개념 및 실습.
MySQL Getting Started BCIS 3680 Enterprise Programming.
Python: File Directories What is a directory? A hierarchical file system that contains folders and files. Directory (root folder) Sub-directory (folder.
CIT 590 Intro to Programming Lecture 6. Vote in the doodle poll so we can use some fancy algorithm to pair you up You.
Outline of Script Import Modules Setup Workspace Environment and Assign Data Path Variables Summary of Script Title and Author Info.
The GWB installation directory must be in your Path
Python’s Modules Noah Black.
Python Lesson 12 Mr. Kalmes.
IST256 : Applications Programming for Information Systems
CSC1018F: Functional Programming
Python Lesson 12 Mr. Kalmes.
While Loops Chapter 3.
Ruth Anderson UW CSE 160 Winter 2016
LING 388: Computers and Language
Ruth Anderson UW CSE 160 Winter 2017
Ruth Anderson UW CSE 160 Spring 2018
Today’s lesson – Python next steps
Fundamentals of Programming I Files
Notes about Homework #4 Professor Hugh C. Lauer CS-1004 — Introduction to Programming for Non-Majors (Slides include materials from Python Programming:
LING 388: Computers and Language
Scripts In Matlab.
Python Modules.
Bryan Burlingame 17 April 2019
Introduction to Computer Science
Input and Output Python3 Beginner #3.
Python 12 Mr. Husch.
The Python interpreter
Lists Like tuples, but mutable. Formed with brackets: Assignment: >>> a = [1,2,3] Or with a constructor function: a = list(some_other_container) Subscription.
Presentation transcript:

Tips

Iteration On a list: o group = ["Paul","Duncan","Jessica"] for person in group: print(group) On a dictionary: o stock = {'eggs':15, 'milk':3, 'sugar':28} Iterate over keys: o for ingredient in stock.iterkeys(): Iterate over values: o for count in stock.itervalues(): Iterate over both: o for ingredient,count in stock.iteritems()

Working directory The Python sessions working directory is set as the directory from where Python is called. This also applies when, in Windows, you edit a file in IDLE. In Windows, the "Start in"-property of a shortcut determines the working directory. If it is empty, the directory where the shortcut is placed is used. To change the working directory from within Python: o import os os.getcwd() # get current working directory os.chdir(path) # change working directory

Executing a script file To execute a script file, from a console write: o python scriptfile.py (This requires the python directory is in the PATH environment variable.) It is possible to pass arguments to the script: o python script arg1 arg2 In the script file, the arguments can be found in the variable sys.argv (remember to import sys ).

Executing a script file To differentiate a script from being run as a module or as a independent script, do as below: o if __name__ == '__main__': # Suite to be executed when script # is called independentantly. Code outside the if-blocks suite, is always executed.