Python’s Standard Library Part II Dennis Tran. Output Formatting The repr module provides a version of repr() customized for abbreviated displays of large.

Slides:



Advertisements
Similar presentations
Chapter 6 Server-side Programming: Java Servlets
Advertisements

Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 15 Introduction to Rails.
Fundamentals of Python: From First Programs Through Data Structures Chapter 2 Software Development, Data Types, and Expressions.
Chapter 3: Beginning Problem Solving Concepts for the Computer Programming Computer Programming Skills /1436 Department of Computer Science.
C o n f i d e n t i a l Developed By Nitendra NextHome Subject Name: Data Structure Using C Unit : Overview of Queues.
PYTHON’S STANDARD LIBRARY – PART II. Repr() Similar use to str() Used to return Python object representation that evaluates to such objects Useful for.
Slide 1 Word Processing. Slide 2 What is a word processor? A word processor is a computer that you use for writing, editing and printing text. A dedicated.
Chapter 2: Algorithm Discovery and Design
1 Lecture 2  Input-Process-Output  The Hello-world program  A Feet-to-inches program  Variables, expressions, assignments & initialization  printf()
Linux+ Guide to Linux Certification, Second Edition
Program Design and Development
Now, return to the Unix Unix shells: Subshells--- Variable---1. Local 2. Environmental.
Inter Process Communication:  It is an essential aspect of process management. By allowing processes to communicate with each other: 1.We can synchronize.
Linux+ Guide to Linux Certification, Second Edition
1 Key Concepts:  Why C?  Life Cycle Of a C program,  What is a computer program?  A program statement?  Basic parts of a C program,  Printf() function?
CS201 – Expressions & I/O. Precedence What is the value of * 4 ? 20 or 14 ? Without parentheses, there are a set of rules to fall back on. Unary.
Chapter 6 C Arrays Acknowledgment The notes are adapted from those provided by Deitel & Associates, Inc. and Pearson Education Inc. Arrays are data structures.
Chapter 2: Algorithm Discovery and Design
Programming Logic and Design, Introductory, Fourth Edition1 Understanding Computer Components and Operations (continued) A program must be free of syntax.
Chapter 2: Algorithm Discovery and Design
 2004 Prentice Hall, Inc. All rights reserved. Chapter 25 – Perl and CGI (Common Gateway Interface) Outline 25.1 Introduction 25.2 Perl 25.3 String Processing.
AIT 616 Fall 2002 PHP. AIT 616 Fall 2002 PHP  Special scripting language used to dynamically generate web documents  Open source – Free!!!  Performs.
C Programming Lecture 3. The Three Stages of Compiling a Program b The preprocessor is invoked The source code is modified b The compiler itself is invoked.
INTERNET APPLICATION DEVELOPMENT For More visit:
CIS Computer Programming Logic
Lists in Python.
Week 7 Working with the BASH Shell. Objectives  Redirect the input and output of a command  Identify and manipulate common shell environment variables.
Chapter Four UNIX File Processing. 2 Lesson A Extracting Information from Files.
Computer Science 111 Fundamentals of Programming I Number Systems.
Fundamentals of Python: First Programs
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 2 Input, Processing, and Output.
WHAT IS A DATABASE? A database is an organized collection of related information. A DB organizes and stores information. an organized collection of related.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley STARTING OUT WITH Python Python First Edition by Tony Gaddis Chapter 2 Input,
Input, Output, and Processing
Shell Script Programming. 2 Using UNIX Shell Scripts Unlike high-level language programs, shell scripts do not have to be converted into machine language.
Linux+ Guide to Linux Certification, Third Edition
Linux+ Guide to Linux Certification Chapter Eight Working with the BASH Shell.
 Pearson Education, Inc. All rights reserved Introduction to Java Applications.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 2 Input, Processing, and Output.
Guide to Oracle 10g ITBIS373 Database Development Lecture 4a - Chapter 4: Using SQL Queries to Insert, Update, Delete, and View Data.
Data TypestMyn1 Data Types The type of a variable is not set by the programmer; rather, it is decided at runtime by PHP depending on the context in which.
Introducing Python CS 4320, SPRING Resources We will be following the Python tutorialPython tutorial These notes will cover the following sections.
© All rights reserved. U.S International Tech Support
Introducing Python CS 4320, SPRING Lexical Structure Two aspects of Python syntax may be challenging to Java programmers Indenting ◦Indenting is.
CSC 1010 Programming for All Lecture 3 Useful Python Elements for Designing Programs Some material based on material from Marty Stepp, Instructor, University.
Advanced Repetition Structure and String Functions (Unit 10) Visual Basic for Applications.
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
Data Types and Conversions, Input from the Keyboard CS303E: Elements of Computers and Programming.
C LANGUAGE Characteristics of C · Small size
SAP DEVELOPMENT BASICS Bohuslav Tesar. TRAINING OVERVIEW Amazing life of ABAP developer ;) SAP introduction ABAP basics ABAP Reporting.
Chapter 15 Strings as Character Arrays
SIDHANT GARG.  Python comes with a bevy of pre-written pieces of programming code for you to use in your programs. The individual files are called modules,
CHAPTER 2 PROBLEM SOLVING USING C++ 1 C++ Programming PEG200/Saidatul Rahah.
Data Types and Conversions, Input from the Keyboard If you can't write it down in English, you can't code it. -- Peter Halpern If you lie to the computer,
Linux+ Guide to Linux Certification, Second Edition Chapter 4 Exploring Linux Filesystems.
Python’s Standard Library Part 2 Francis Ryan. Output formatting, 1 repr module – When using large or deeply nested containers, allows better printing.
Linux+ Guide to Linux Certification, Second Edition
Chapter – 8 Software Tools.
Dept. of Animal Breeding and Genetics Programming basics & introduction to PERL Mats Pettersson.
Linux Administration Working with the BASH Shell.
Lesson 17 Mail Merge. Overview Create a main document. Create a data source. Insert merge fields into a main document. Perform a mail merge. Use data.
Lesson 5-Exploring Utilities
CS 330 Class 7 Comments on Exam Programming plan for today:
Data Types and Conversions, Input from the Keyboard
Variables, Expressions, and IO
Python Libraries II By Michael Valle.
Introduction to Python
Python’s Standard Library Part II
Python’s STD Library Part II.
Presentation transcript:

Python’s Standard Library Part II Dennis Tran

Output Formatting The repr module provides a version of repr() customized for abbreviated displays of large or deeply nested containers The pprint module offers more sophisticated control over printing objects in a way readable by the interpreter  “pretty printer” adds appropriate line breaks and indentation when the result is more than one line

Output formatting Can use the textwrap module to format paragraphs of text to fit a given screen width The locale module access a database of cultural specific data formats  Allows programmers to deal with certain cultural issues in an application w/out knowing all the specifics of where the SW is executed

Templating The string module includes a Template class with a simplified syntax suitable for editing by end users  Format uses placeholder names formed by $ substitute() method performs template substitution, returning a new string “$$” creates a single escaped $ Surround placeholder with “{ }” to follow it with more alphanumeric characters

Working with Binary Data Record Layouts The struct module provides pack() and unpack() functions for working with variable length binary record formats  Example below shows how to loop through header info in a ZIP file w/out using the zipfile module Pack codes “H” and “I” represent two and four byte unsigned integers “<“ indicates pack codes are standard size and in little-endian byte order

Multi-threading Use the threading module to run tasks in the background while the main program runs  After creating a thread object, call the start() method to invoke the run() method in a separate thread of control  join() method waits until a thread terminates

Logging The logging module offers a full featured and flexible logging system for applications  Log messages usually sent to a file or sys.stderr Example:  Produces the following output: Other output options include routing messages through , datagrams, sockets, or an HTTP server

Weak References The weakref module provides tools to track objects without creating references  When an object is no longer needed, it is automatically removed from the weakref table and a callback is triggered for weakref objects WeakKeyDictionar y is a mapping class that references keys weakly Entries in dictionary are destroyed when there is no longer a strong reference to the key

Tools for Working with Lists The array module provides an array() object that stores data of a single type more compactly  Typecode “H” represents two byte unsigned binary numbers The collections module provides a deque() object with fast appends and O(1) pops from either side; good for implementing queues and breadth first tree searches

Tools for Working with Lists The bisect module contains functions for manipulating sorted lists  Implements bisection algorithm The heapq module provides functions for implementing heaps based on regular lists  Implements the heap queue algorithm  Smallest valued entry always kept at position 0

Decimal Floating Point Arithmetic The decimal module can be used for decimal floating point arithmetic Useful for:  Financial applications that require exact decimal representation  Control over precision  Control over rounding to meet legal or regulatory requirements  Tracking of significant figures  Applications where the results should match hand calculations Difference of results between decimal floating point and binary floating point:

Decimal Floating Point Arithmetic Exact representation enables the Decimal class to perform modulo calculations and equality tests where binary floating point would fail: decimal module also provides arithmetic with as much precision as needed  Using getcontext().prec method to set # of decimal places:

References Python v2.7.1 documentation  “11. Brief Tour of the Standard Library Part II”  “The Python Standard Library”