Python 4: Advanced Python - Bob Belderbos

Python 4: Advanced Python

Lesso n 1: Go ing Furt he r wit h Funct io ns Abo ut Eclipse Perspectives and the Red Leaf Ico n Wo rking Sets

Functio ns Are Objects Functio n Attributes Functio n and Metho d Calls Functio n Co mpo sitio n Lambdas: Ano nymo us Functio ns

Quiz 1 Pro ject 1 Lesson 2: Dat a St ruct ures

Organizing Data Handling Multi-Dimensio nal Arrays in Pytho n

Creating a Two -Dimensio nal Array List o f Lists Example Using a Single List to Represent an Array Using an array.array instead o f a List Using a dict instead o f a List

Sum m ary Quiz 1 Pro ject 1

Lesson 3: Delegat io n and Co mpo sit io n Extending Functio nality by Inheritance Mo re Co mplex Delegatio n Extending Functio nality by Co mpo sitio n Recursive Co mpo sitio n Quiz 1 Pro ject 1

Lesson 4: Publish and Subscribe On Pro gram Structure Publish and Subscribe Publish and Subscribe in Actio n Validating Requests and Identifying Output Making the Algo rithm Mo re General

A No te o n Debugging Quiz 1 Pro ject 1

Lesso n 5: Opt im izing Yo ur Co de Start with Co rrectness Where to Optimize

The Pro file Mo dule Two Different Mo dules Using the Pro file Mo dule Mo re Co mplex Repo rting

What to Optimize Lo o p Optimizatio ns

Pre-co mputing Attribute References Lo cal Variables are Faster than Glo bal Variables

Ho w to Optimize Do n't Optimize Prematurely Use Timings, No t Intuitio n Make One Change at a Time The Best Way is No t Always Obvio us

Quiz 1 Pro ject 1 Lesso n 6 : Using Exce pt io ns Wise ly

Exceptio ns Are No t (Necessarily) Erro rs Specifying Exceptio ns

Creating Exceptio ns and Raising Instances Using Exceptio ns Wisely

Exceptio n Timings

Quiz 1 Pro ject 1 Lesson 7: Advanced Uses o f Deco rat o rs

Deco rato r Syntax Classes as Deco rato rs Class Deco rato rs Odd Deco rato r Tricks Static and Class Metho d Deco rato rs Parameterizing Deco rato rs

Quiz 1 Pro ject 1 Lesson 8: Advanced Generat o rs

What Generato rs Represent Uses o f Infinite Sequences The Iterto o ls Mo dule

iterto o ls.tee: duplicating generato rs iterto o ls.chain() and iterto o ls.islice(): Co ncatenating Sequences and Slicing Generato rs Like Lists iterto o ls.co unt(), iterto o ls.cycle() and iterto o ls.repeat() iterto o ls.dro pwhile() and iterto o ls.takewhile()

Generato r Expressio ns Quiz 1 Pro ject 1

Lesson 9: Uses o f Int ro spect io n The Meaning o f 'Intro spectio n' So me Simple Intro spectio n Examples

Attribute Handling Functio ns What Use is Intro spectio n? The Inspect mo dule

The getmembers() Functio n Intro specting Functio ns

Quiz 1 Pro ject 1 Lesso n 10 : Mult i-T hre ading

Threads and Pro cesses

Multipro gramming Multipro cessing Multi- Threading Threading, Multipro cessing, CPytho n and the GIL

The Threading Library Mo dule Creating Threads (1) Waiting fo r Threads Creating Threads (2)

Quiz 1 Pro ject 1 Lesso n 11: Mo re o n Mult i-T hre ading

Thread Synchro nizatio n threading.Lo ck Objects

The Queue Standard Library Adding Items to Queues: Queue.put() Remo ving Items fro m Queues: Queue.get() Mo nito ring Co mpletio n: Queue.task_do ne() and Queue.jo in() A Simple Scalable Multi-Threaded Wo rkho rse The Output Thread The Wo rker Threads The Co ntro l Thread Other Appro aches

Quiz 1 Pro ject 1 Lesso n 12: Mult i-Pro ce ssing

The Multipro cessing Library Mo dule multipro cessing Objects A Simple Multipro cessing Example

A Multipro cessing Wo rker Pro cess Po o l The Output Pro cess The Wo rker Pro cess The Co ntro l Pro cess

Quiz 1 Pro ject 1 Lesso n 13: Funct io ns and Ot he r Obje ct s

A Deeper Lo o k at Functio ns Required Keywo rd Arguments Functio n Anno tatio ns Nested Functio ns and Namespaces Partial Functio ns

Mo re Magic Metho ds Ho w Pytho n Expressio ns Wo rk

Quiz 1 Pro ject 1 Lesso n 14: Co nt e xt Manage rs

Ano ther Pytho n Co ntro l Structure: The With Statement Using a Simple Co ntext Manager The Co ntext Manager Pro to co l: __enter__() and __exit__() Writing Co ntext Manager Classes Library Suppo rt fo r Co ntext Managers

Nested Co ntext Managers

Decimal Arithmetic and Arithmetic Co ntexts Decimal Arithmetic Co ntexts Decimal Signals The Default Decimal Co ntext

Quiz 1 Pro ject 1 Lesso n 15: Me m o ry-Mappe d File s

Memo ry Mapping Memo ry-Mapped Files Are Still Files The mmap Interface What Use is mmap(), and Ho w Do es it Wo rk?

A Memo ry-Mapped Example Quiz 1 Pro ject 1

Lesso n 16 : Yo ur Fut ure wit h Pyt ho n Pytho n Co nferences Tuto rials Talks The Hallway Track Open Space Lightning Talks Birds o f a Feather Sessio ns (BOFs) Sprints: Mo ving Ahead

The Pytho n Jo b Market and Career Cho ices Pytho n Develo pment Tips and Tricks

Quiz 1 Pro ject 1

Copyright ? 1998-2014 O'Reilly Media, Inc.

This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License. See for more information.

Going Further with Functions

Welco me to the O'Reilly Scho o l o f Techno lo gy (OST) Advanced Pytho n co urse! We're happy yo u've cho sen to learn Pytho n pro gramming with us. By the time yo u finish this co urse, yo u will have expanded yo ur kno wledge o f Pytho n and applied it to so me really interesting techno lo gies.

Course Objectives

When yo u co mplete this co urse, yo u will be able to :

extend Pytho n co de functio nality thro ugh inheritance, co mplex delegatio n, and recursive co mpo sitio n. publish, subscribe, and o ptimize yo ur co de. create advanced class deco rato rs and generato rs in Pytho n. demo nstrate kno wledge o f Pytho n intro spectio n. apply multi-threading and mult-pro cessing to Pytho n develo pment. manage arithmetic co ntexts and memo ry mapping. demo nstrate understanding o f the Pytho n co mmunity, co nferences, and jo b market. develo p a multi-pro cessing so lutio n to a significant data pro cessing pro blem.

This co urse builds o n yo ur existing Pytho n kno wledge, inco rpo rating further o bject-o riented design principles and techniques with the intentio n o f ro unding o ut yo ur skill set. Techniques like recursio n, co mpo sitio n, and delegatio n are explained and put into practice thro ugh the ever-present test-driven practical wo rk.

Learning with O'Reilly School of T echnology Courses

As with every O'Reilly Scho o l o f Techno lo gy co urse, we'll take a user-active appro ach to learning. This means that yo u (the user) will be active! Yo u'll learn by do ing, building live pro grams, testing them and experimenting with them-- hands - o n!

To learn a new skill o r techno lo gy, yo u have to experiment. The mo re yo u experiment, the mo re yo u learn. Our system is designed to maximize experimentatio n and help yo u learn to learn a new skill.

We'll pro gram as much as po ssible to be sure that the principles sink in and stay with yo u.

Each time we discuss a new co ncept, yo u'll put it into co de and see what YOU can do with it. On o ccasio n we'll even give yo u co de that do esn't wo rk, so yo u can see co mmo n mistakes and ho w to reco ver fro m them. Making mistakes is actually ano ther go o d way to learn.

Abo ve all, we want to help yo u to learn to learn. We give yo u the to o ls to take co ntro l o f yo ur o wn learning experience.

When yo u co mplete an OST co urse, yo u kno w the subject matter, and yo u kno w ho w to expand yo ur kno wledge, so yo u can handle changes like so ftware and o perating system updates.

Here are so me tips fo r using O'Reilly Scho o l o f Techno lo gy co urses effectively:

T ype t he co de . Resist the temptatio n to cut and paste the example co de we give yo u. Typing the co de actually gives yo u a feel fo r the pro gramming task. Then play aro und with the examples to find o ut what else yo u can make them do , and to check yo ur understanding. It's highly unlikely yo u'll break anything by experimentatio n. If yo u do break so mething, that's an indicatio n to us that we need to impro ve o ur system! T ake yo ur t im e . Learning takes time. Rushing can have negative effects o n yo ur pro gress. Slo w do wn and let yo ur brain abso rb the new info rmatio n tho ro ughly. Taking yo ur time helps to maintain a relaxed, po sitive appro ach. It also gives yo u the chance to try new things and learn mo re than yo u o therwise wo uld if yo u blew thro ugh all o f the co ursewo rk to o quickly. Expe rim e nt . Wander fro m the path o ften and explo re the po ssibilities. We can't anticipate all o f yo ur questio ns and ideas, so it's up to yo u to experiment and create o n yo ur o wn. Yo ur instructo r will help if yo u go co mpletely o ff the rails. Acce pt guidance , but do n't de pe nd o n it . Try to so lve pro blems o n yo ur o wn. Go ing fro m misunderstanding to understanding is the best way to acquire a new skill. Part o f what yo u're learning is pro blem so lving. Of co urse, yo u can always co ntact yo ur instructo r fo r hints when yo u need them. Use all available re so urce s! In real-life pro blem-so lving, yo u aren't bo und by false limitatio ns; in OST co urses, yo u are free to use any reso urces at yo ur dispo sal to so lve pro blems yo u enco unter: the Internet, reference bo o ks, and o nline help are all fair game.

................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download