SlideShare a Scribd company logo
Slide 1
------------
Python - why settle for snake oil when you can have the whole snake?

Slide 2
------------
* This is a workshop, not a talk.
* You are expected to code along.
* So pull out your laptops, and
* Install python, ipython and komodo edit. (Or editor of your choice.)

Slide 3
------------
* Assume that you know programming in any language.
* So we dont spend a lot of time explaining basics.
* BUT, stop and ask if something doesn't make sense.
* AND Definately Stop me if I am going too slow, too fast, or making no sense.

Slide 4
------------
* Python *

* Dynamically but strongly typed.
* Very object oriented - everything is an object.
* But pragmatic - Objects aren't everthing.
* Allows various paradigms of programming - OO, procedural, functional.
* Shallow learning curve, but powerful powerful capabilities avaialble, when you
need them.
* import this
* We will come back to this slide.

Slide 4.1
-----------
* Hello world *

>>> print "Hello World"

Slide 5
-------------
* Lets start *

*   The control structures.
*   for, while, if, else, break, continue
*   -Yeah they are available, surprised?
*   We will use them in a moment, but after we see the data structures available.


Slide 6
----------

* The data strcutures *

* List - Like ArrayList in Java
* Tuple - Like List, but immutable
* Dict - Like Hashmaps in Java

--Hid

In [1]: v1 = [1, 2, 3, 4, 5]

In [2]: v2 = (1, 2, 3, 4, 5)
In [3]: v3 = {1:'a', 2:'b'}

In [4]: type(v1)
Out[4]: <type 'list'>

In [5]: type(v2)
Out[5]: <type 'tuple'>

In [6]: type(v3)
Out[6]: <type 'dict'>

Slide 7
-----------
* The control structures. *

* For Loop
* for el in iterable:
    [block statement]
* the classic for loop
* for (int i; i < n; i++){}
* for i in range(n):
    #Work with i
* while condition:
    [block]
* break, continue. Normal operation - break out of current loop.


--Hidden--
In [10]: for el in v1:
   ....:     print el
   ....:
   ....:
1
2
3
4
5

In [11]: x = 5

In [12]: while x < 100:
   ....:     print x
   ....:     x = x * 2
   ....:
   ....:
5
10
20
40
80

Slide 8
--------------

Conditionals
--------------
*If: elif: else:*

*   if condition:
        [block]
    else:
        [block]
--Hidden--

       In [15]: if f == 10:
      ....:     print 'Ten'
      ....: else:
      ....:     print 'Not 10'
      ....:
      ....:
Ten

if f == 12:
    print 'Ten'
 else:
    print 'Not 10'

Slide 9
--------------

* The fizzbuzz test *
* You have enough information now to write a solution
* Problem statement
Write a program that prints the numbers from 1 to 100. But for multiples of
three print "Fizz" instead of the number and for the multiples of five print
"Buzz". For numbers which are multiples of both three and five print "FizzBuzz".

--Hidden---
Give time here

[Wrong]
for i in range(1, 101):
    if i % 3 == 0:
        print 'fizz'
    elif i % 5 == 0:
        print 'buzz'
    elif i % 15 == 0:
        print 'fizzbuzz'
    else:
        print i

[One sol]

for i in range(1, 101):
    if i % 15 == 0:
        print 'fizzbuzz'
    elif i % 3 == 0:
        print 'fizz'
    elif i % 5 == 0:
        print 'buzz'

      else:
          print i

Slide 10
------------

* Functions *

def function_name(argument_list):
    [block]

* Functions can have default value.
def fizzbuzz(till=100, fizz='fizz', buzz='buzz'):
    #fizzbuzz code

* Functions can have variable length values.

ex multiply all values passed to a function.

* Functions are first class - They are objects too. They can be passed to other
functions, assigned to variables etc.

--Hidden--
In [33]: def func():
   ....:     pass
   ....:

In [34]: type(func)
Out[34]: <type 'function'>

In [35]: def mult_all(*args):
   ....:     i = 1
   ....:     for el in args:
   ....:         i = i * el
   ....:
   ....:     return i
   ....:

In [36]: mult_all(2, 3, 4, 5)
Out[36]: 120

Slide 11
-----------
* Classes *

class ClassName(base_classes):
    [block]

* Classes are first class too
* They can be passed to function, and assigned to variables.

---Hiden---

class Accounts(object):
    def __init__(self, account_holder, initial_deposit):
        self.account_holder = account_holder
        self.money_available = initial_deposit
        self.history = []

    def withdraw(self, amount):
        self.money_available = self.money_available - amount
        self.history.append('Withdrew %s'%amount)

    def deposit(self, amount):
        self.money_available = self.money_available + amount
        self.history.append('Deposited %s'%amount)

    def __str__(self):
        return "%s has %s available." % (self.account_holder,
self.money_available)

    def __repr__(self):
        return str(self)
Slide 12
-----------

* Time for another problem *

* Project euler: problem 1

If we list all the natural numbers below 10 that are multiples of 3 or 5, we get
3, 5, 6 and 9. The sum of these multiples is 23.

Find the sum of all the multiples of 3 or 5 below 1000

--hidden--
In [15]: sum = 0

In [16]: for i in range(1000):

Display all 213 possibilities? (y or n)

In [16]: for i in range(1000):

   ....:      if i % 3 == 0 or i % 5 == 0:
   ....:          sum += i
   ....:
   ....:

In [18]: print sum
-------> print(sum)
233168


Slide 13
-----------
* Here comes the list comprehensions *

* The last sulotion was needlessly verbose
* List comprehension: Take a list and transform it.
* Standard list comrehension syntax - [expr(i) for i in iterable if condition]
* List of all squares: [i*i for i in range(1,11)]
* List of all squares of even numbers: [i*i for i in range(1,11) if i%2 == 0]
* So solution to last problem is just
sum([i*i for i in range(1,1001) if i%3 == 0 or i%5==0])

--Hidden--
In [19]: [i*i for i in range(1,11)]
Out[19]: [1, 4, 9, 16, 25, 36, 49, 64, 81, 100]
In [1]: sum([i*i for i in range(1,1001) if i%3 == 0 or i%5==0])
Out[1]: 156390386

Slide 14
-----------
*Some functional programming*

* List comprehensions are python way to do functional programming constructs
* [function(i) for i in iterable if condition] is filter(func2, map(func1,
iter))
* Lets see how this list comprehension maps to functional concepts
* Get the list of squares of even numbers

--Hidden--
In [5]: filter(lambda x: x%2==0, map(lambda x: x ** 2, range(1, 11)))
Out[5]: [4, 16, 36, 64, 100]

In [6]: [el*el for el in range(1, 11) if el%2 ==0]
Out[6]: [4, 16, 36, 64, 100]

Slide 15
--------------
*File Handling*

* Open a file with - open('location') or file('location')
* or give a mode - open('location', 'rw')
* iterate as
for line in open_file.readlines():
    print line#Or whatvere

or
string = open_file.read()


--Hidden--

In [8]: open_file = open('/home/shabda/python_talk/11.txt')

In [9]: for el in open_file.readlines():
   ...:     print el
   ...:     break
   ...:
   ...:
Project Gutenberg's Alice's Adventures in Wonderland, by Lewis Carroll


Slide 16
--------------

*Some actual work*

Find the most commonly used word in the Alice in wonderland text.

--Hidden--
Give time here

#!/usr/bin/env python
from operator import itemgetter

open_file = open('/home/shabda/python_talk/11.txt')
text = open_file.read()
words = text.split()
word_count = {}
for word in words:
    if word in word_count:
        word_count[word] += 1
    else:
        word_count[word] = 1

sorted_list = sorted(word_count.items(), key=itemgetter(1), reverse=True)
print sorted_list[0]


Slide 17
------------
* Problems *
* Ok, now you suggets some problems and lets solve them together.

Slide 18
-------------
* A tour of the standard library *

*   Batteries included
*   math
*   datetime
*   string
*   re
*   random
*   os
*   pickle
*   Do a dir and see for yourself.

And a lot, lot more
http://docs.python.org/library/

--hidden--
Spend time here

In [14]: math.cos(math.pi)
Out[14]: -1.0

In [9]: datetime.date.today() > datetime.date(2008, 9, 12)
Out[9]: True

In [18]: string.capitalize('python is a programming language.')
Out[18]: 'Python is a programming language.'




In [19]: import random

In [20]: random.choice(['ubuntu', 'redhat', 'xandros'])
Out[20]: 'xandros'

In [21]: random.choice(['ubuntu', 'redhat', 'xandros'])
Out[21]: 'ubuntu'

Slide 19
-------------

* Back to slide 4 *

* Dynamically but strongly typed.
* Very object oriented - everything is an object.
* But pragmatic - Objects aren't everthing.
* Allows various paradigms of programming - OO, procedural, functional.
* Shallow learning curve, but powerful powerful capabilities avaialble, when you
need them.
* import this

--Hidden--
Explain.

* Slide 20 *
---------------
* Decorators *
Syntacting sugar for
foo_func =docorator_func(foo_func)

--Hidden--

In [1]: def good_function():
   ...:     print 'I am a good function'
   ...:
   ...:

In [2]: def decorator(orig_func):
   ...:     def bad_func():
   ...:         print 'I am a bad function'
   ...:     return bad_func
   ...:

In [3]: good_function = decorator(good_function)

In [4]: good_function()
I am a bad function

In [5]: @decorator
   ....: def good_function2():
   ....:     print 'I am a good function'
   ....:
   ....:

In [6]: good_function2()
I am a bad function


#!/usr/bin/env python

def is_val_positive_deco(orig_func):
        def temp_func(val):
                if val < 0:
                         return 0
                else:
                         return orig_func(val)
        return temp_func

@is_val_positive_deco
def sqrt(val):
        import math
        return math.pow(val, (1.0/2))

print sqrt(-1)
print sqrt(4)

Slide 21
---------------
* Web development with Python *

* Many useful frameworks
* Django
* GAE
* Turbogears
* We recommend Django - Most actively developed and largest community
participation


Slide 22
----------
*If we have time*
* PIL - Image Manipulation
* Mechanize - Browser automation
* Beautiful Soup - Html extraction.

Slide 23
-------------
* Resources *
python.org
diveintopython.org
uswaretech.com/blog

Slide 24
----------
* Thank You. *
You can give feedback, ask questions at shabda@uswaretech.com

More Related Content

PDF
Beginning Python
PDF
MP in Clojure
PDF
Free Monads Getting Started
PDF
The best of AltJava is Xtend
PPT
Python легко и просто. Красиво решаем повседневные задачи
PPTX
TCO in Python via bytecode manipulation.
PDF
Python opcodes
PDF
Lucio Floretta - TensorFlow and Deep Learning without a PhD - Codemotion Mila...
Beginning Python
MP in Clojure
Free Monads Getting Started
The best of AltJava is Xtend
Python легко и просто. Красиво решаем повседневные задачи
TCO in Python via bytecode manipulation.
Python opcodes
Lucio Floretta - TensorFlow and Deep Learning without a PhD - Codemotion Mila...

What's hot (20)

PDF
Introducción a Elixir
PDF
"Немного о функциональном программирование в JavaScript" Алексей Коваленко
PPTX
Dts x dicoding #2 memulai pemrograman kotlin
PDF
Are we ready to Go?
PDF
4. Обработка ошибок, исключения, отладка
PDF
C++ L05-Functions
PDF
Design Pattern Observations
PDF
PythonOOP
PPT
Collection Core Concept
PDF
Functional Algebra: Monoids Applied
PDF
C++ L01-Variables
PPTX
Python
PPTX
Type Driven Development with TypeScript
PDF
The best language in the world
PDF
Why Haskell
PDF
Imugi: Compiler made with Python
PDF
The Ring programming language version 1.7 book - Part 35 of 196
PDF
T3chFest 2016 - The polyglot programmer
PDF
C++ L04-Array+String
PDF
Being functional in PHP (PHPDay Italy 2016)
Introducción a Elixir
"Немного о функциональном программирование в JavaScript" Алексей Коваленко
Dts x dicoding #2 memulai pemrograman kotlin
Are we ready to Go?
4. Обработка ошибок, исключения, отладка
C++ L05-Functions
Design Pattern Observations
PythonOOP
Collection Core Concept
Functional Algebra: Monoids Applied
C++ L01-Variables
Python
Type Driven Development with TypeScript
The best language in the world
Why Haskell
Imugi: Compiler made with Python
The Ring programming language version 1.7 book - Part 35 of 196
T3chFest 2016 - The polyglot programmer
C++ L04-Array+String
Being functional in PHP (PHPDay Italy 2016)
Ad

Similar to Talk Code (20)

PPTX
Python Workshop - Learn Python the Hard Way
ODP
Python basics
PDF
Raspberry Pi - Lecture 5 Python for Raspberry Pi
PDF
Introduction To Programming with Python
PDF
Python Part 1
PDF
Python cheatsheat.pdf
PPTX
(OOP Lec2) Basics of Python Programming.pptx
PPTX
Introduction to the basics of Python programming (part 3)
PDF
PyLecture4 -Python Basics2-
PPT
python language programming presentation
PDF
python.pdf
PDF
Pythonintro
PDF
Python_ 3 CheatSheet
PDF
Introduction to python
PPT
Python Training v2
PDF
Introduction to Python
PPTX
Python bible
PDF
Python for everybody
PPTX
An Introduction : Python
Python Workshop - Learn Python the Hard Way
Python basics
Raspberry Pi - Lecture 5 Python for Raspberry Pi
Introduction To Programming with Python
Python Part 1
Python cheatsheat.pdf
(OOP Lec2) Basics of Python Programming.pptx
Introduction to the basics of Python programming (part 3)
PyLecture4 -Python Basics2-
python language programming presentation
python.pdf
Pythonintro
Python_ 3 CheatSheet
Introduction to python
Python Training v2
Introduction to Python
Python bible
Python for everybody
An Introduction : Python
Ad

Recently uploaded (20)

PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PPTX
Programs and apps: productivity, graphics, security and other tools
PDF
Empathic Computing: Creating Shared Understanding
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
cuic standard and advanced reporting.pdf
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
Approach and Philosophy of On baking technology
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PPTX
Spectroscopy.pptx food analysis technology
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Review of recent advances in non-invasive hemoglobin estimation
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Dropbox Q2 2025 Financial Results & Investor Presentation
Advanced methodologies resolving dimensionality complications for autism neur...
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Programs and apps: productivity, graphics, security and other tools
Empathic Computing: Creating Shared Understanding
20250228 LYD VKU AI Blended-Learning.pptx
Understanding_Digital_Forensics_Presentation.pptx
cuic standard and advanced reporting.pdf
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Approach and Philosophy of On baking technology
Mobile App Security Testing_ A Comprehensive Guide.pdf
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Spectroscopy.pptx food analysis technology
Chapter 3 Spatial Domain Image Processing.pdf
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Per capita expenditure prediction using model stacking based on satellite ima...
Review of recent advances in non-invasive hemoglobin estimation
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...

Talk Code

  • 1. Slide 1 ------------ Python - why settle for snake oil when you can have the whole snake? Slide 2 ------------ * This is a workshop, not a talk. * You are expected to code along. * So pull out your laptops, and * Install python, ipython and komodo edit. (Or editor of your choice.) Slide 3 ------------ * Assume that you know programming in any language. * So we dont spend a lot of time explaining basics. * BUT, stop and ask if something doesn't make sense. * AND Definately Stop me if I am going too slow, too fast, or making no sense. Slide 4 ------------ * Python * * Dynamically but strongly typed. * Very object oriented - everything is an object. * But pragmatic - Objects aren't everthing. * Allows various paradigms of programming - OO, procedural, functional. * Shallow learning curve, but powerful powerful capabilities avaialble, when you need them. * import this * We will come back to this slide. Slide 4.1 ----------- * Hello world * >>> print "Hello World" Slide 5 ------------- * Lets start * * The control structures. * for, while, if, else, break, continue * -Yeah they are available, surprised? * We will use them in a moment, but after we see the data structures available. Slide 6 ---------- * The data strcutures * * List - Like ArrayList in Java * Tuple - Like List, but immutable * Dict - Like Hashmaps in Java --Hid In [1]: v1 = [1, 2, 3, 4, 5] In [2]: v2 = (1, 2, 3, 4, 5)
  • 2. In [3]: v3 = {1:'a', 2:'b'} In [4]: type(v1) Out[4]: <type 'list'> In [5]: type(v2) Out[5]: <type 'tuple'> In [6]: type(v3) Out[6]: <type 'dict'> Slide 7 ----------- * The control structures. * * For Loop * for el in iterable: [block statement] * the classic for loop * for (int i; i < n; i++){} * for i in range(n): #Work with i * while condition: [block] * break, continue. Normal operation - break out of current loop. --Hidden-- In [10]: for el in v1: ....: print el ....: ....: 1 2 3 4 5 In [11]: x = 5 In [12]: while x < 100: ....: print x ....: x = x * 2 ....: ....: 5 10 20 40 80 Slide 8 -------------- Conditionals -------------- *If: elif: else:* * if condition: [block] else: [block]
  • 3. --Hidden-- In [15]: if f == 10: ....: print 'Ten' ....: else: ....: print 'Not 10' ....: ....: Ten if f == 12: print 'Ten' else: print 'Not 10' Slide 9 -------------- * The fizzbuzz test * * You have enough information now to write a solution * Problem statement Write a program that prints the numbers from 1 to 100. But for multiples of three print "Fizz" instead of the number and for the multiples of five print "Buzz". For numbers which are multiples of both three and five print "FizzBuzz". --Hidden--- Give time here [Wrong] for i in range(1, 101): if i % 3 == 0: print 'fizz' elif i % 5 == 0: print 'buzz' elif i % 15 == 0: print 'fizzbuzz' else: print i [One sol] for i in range(1, 101): if i % 15 == 0: print 'fizzbuzz' elif i % 3 == 0: print 'fizz' elif i % 5 == 0: print 'buzz' else: print i Slide 10 ------------ * Functions * def function_name(argument_list): [block] * Functions can have default value.
  • 4. def fizzbuzz(till=100, fizz='fizz', buzz='buzz'): #fizzbuzz code * Functions can have variable length values. ex multiply all values passed to a function. * Functions are first class - They are objects too. They can be passed to other functions, assigned to variables etc. --Hidden-- In [33]: def func(): ....: pass ....: In [34]: type(func) Out[34]: <type 'function'> In [35]: def mult_all(*args): ....: i = 1 ....: for el in args: ....: i = i * el ....: ....: return i ....: In [36]: mult_all(2, 3, 4, 5) Out[36]: 120 Slide 11 ----------- * Classes * class ClassName(base_classes): [block] * Classes are first class too * They can be passed to function, and assigned to variables. ---Hiden--- class Accounts(object): def __init__(self, account_holder, initial_deposit): self.account_holder = account_holder self.money_available = initial_deposit self.history = [] def withdraw(self, amount): self.money_available = self.money_available - amount self.history.append('Withdrew %s'%amount) def deposit(self, amount): self.money_available = self.money_available + amount self.history.append('Deposited %s'%amount) def __str__(self): return "%s has %s available." % (self.account_holder, self.money_available) def __repr__(self): return str(self)
  • 5. Slide 12 ----------- * Time for another problem * * Project euler: problem 1 If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23. Find the sum of all the multiples of 3 or 5 below 1000 --hidden-- In [15]: sum = 0 In [16]: for i in range(1000): Display all 213 possibilities? (y or n) In [16]: for i in range(1000): ....: if i % 3 == 0 or i % 5 == 0: ....: sum += i ....: ....: In [18]: print sum -------> print(sum) 233168 Slide 13 ----------- * Here comes the list comprehensions * * The last sulotion was needlessly verbose * List comprehension: Take a list and transform it. * Standard list comrehension syntax - [expr(i) for i in iterable if condition] * List of all squares: [i*i for i in range(1,11)] * List of all squares of even numbers: [i*i for i in range(1,11) if i%2 == 0] * So solution to last problem is just sum([i*i for i in range(1,1001) if i%3 == 0 or i%5==0]) --Hidden-- In [19]: [i*i for i in range(1,11)] Out[19]: [1, 4, 9, 16, 25, 36, 49, 64, 81, 100] In [1]: sum([i*i for i in range(1,1001) if i%3 == 0 or i%5==0]) Out[1]: 156390386 Slide 14 ----------- *Some functional programming* * List comprehensions are python way to do functional programming constructs * [function(i) for i in iterable if condition] is filter(func2, map(func1, iter)) * Lets see how this list comprehension maps to functional concepts * Get the list of squares of even numbers --Hidden-- In [5]: filter(lambda x: x%2==0, map(lambda x: x ** 2, range(1, 11)))
  • 6. Out[5]: [4, 16, 36, 64, 100] In [6]: [el*el for el in range(1, 11) if el%2 ==0] Out[6]: [4, 16, 36, 64, 100] Slide 15 -------------- *File Handling* * Open a file with - open('location') or file('location') * or give a mode - open('location', 'rw') * iterate as for line in open_file.readlines(): print line#Or whatvere or string = open_file.read() --Hidden-- In [8]: open_file = open('/home/shabda/python_talk/11.txt') In [9]: for el in open_file.readlines(): ...: print el ...: break ...: ...: Project Gutenberg's Alice's Adventures in Wonderland, by Lewis Carroll Slide 16 -------------- *Some actual work* Find the most commonly used word in the Alice in wonderland text. --Hidden-- Give time here #!/usr/bin/env python from operator import itemgetter open_file = open('/home/shabda/python_talk/11.txt') text = open_file.read() words = text.split() word_count = {} for word in words: if word in word_count: word_count[word] += 1 else: word_count[word] = 1 sorted_list = sorted(word_count.items(), key=itemgetter(1), reverse=True) print sorted_list[0] Slide 17 ------------ * Problems *
  • 7. * Ok, now you suggets some problems and lets solve them together. Slide 18 ------------- * A tour of the standard library * * Batteries included * math * datetime * string * re * random * os * pickle * Do a dir and see for yourself. And a lot, lot more http://docs.python.org/library/ --hidden-- Spend time here In [14]: math.cos(math.pi) Out[14]: -1.0 In [9]: datetime.date.today() > datetime.date(2008, 9, 12) Out[9]: True In [18]: string.capitalize('python is a programming language.') Out[18]: 'Python is a programming language.' In [19]: import random In [20]: random.choice(['ubuntu', 'redhat', 'xandros']) Out[20]: 'xandros' In [21]: random.choice(['ubuntu', 'redhat', 'xandros']) Out[21]: 'ubuntu' Slide 19 ------------- * Back to slide 4 * * Dynamically but strongly typed. * Very object oriented - everything is an object. * But pragmatic - Objects aren't everthing. * Allows various paradigms of programming - OO, procedural, functional. * Shallow learning curve, but powerful powerful capabilities avaialble, when you need them. * import this --Hidden-- Explain. * Slide 20 * --------------- * Decorators *
  • 8. Syntacting sugar for foo_func =docorator_func(foo_func) --Hidden-- In [1]: def good_function(): ...: print 'I am a good function' ...: ...: In [2]: def decorator(orig_func): ...: def bad_func(): ...: print 'I am a bad function' ...: return bad_func ...: In [3]: good_function = decorator(good_function) In [4]: good_function() I am a bad function In [5]: @decorator ....: def good_function2(): ....: print 'I am a good function' ....: ....: In [6]: good_function2() I am a bad function #!/usr/bin/env python def is_val_positive_deco(orig_func): def temp_func(val): if val < 0: return 0 else: return orig_func(val) return temp_func @is_val_positive_deco def sqrt(val): import math return math.pow(val, (1.0/2)) print sqrt(-1) print sqrt(4) Slide 21 --------------- * Web development with Python * * Many useful frameworks * Django * GAE * Turbogears * We recommend Django - Most actively developed and largest community participation Slide 22
  • 9. ---------- *If we have time* * PIL - Image Manipulation * Mechanize - Browser automation * Beautiful Soup - Html extraction. Slide 23 ------------- * Resources * python.org diveintopython.org uswaretech.com/blog Slide 24 ---------- * Thank You. * You can give feedback, ask questions at shabda@uswaretech.com