Danny Adair - Python Cookbook - Intro

Loading...

Flash Player 9 (or above) is needed to view presentations.
We have detected that you do not have it on your computer. To install it, go here.

0 comments

Post a comment

    Post a comment
    Embed Video
    Edit your comment Cancel

    1 Favorite & 1 Group

    Danny Adair - Python Cookbook - Intro - Presentation Transcript

    1. Python Cookbook - Intro
        The series will give you solutions through:
      • Understanding of Python's language features
      • Implementations of common design patterns in Python
    2. The Arsenal
      • Specific solutions to specific problems
      • Python Language features
      • Design patterns
      • If you have a specific problem -
      • you know what to Google for!
      • What if you (think you) don't?
      • Better name for this series? Please tell me!
    3. TODAY Confirming a need
    4. Know your Python?
      • Descriptor
      • Decorator
      • Generator
      • Iterator
      • Meta class
      • List comprehension
      • Lambda
      • Set
      • Queue
      • Threading
      • Closure
      • ...
    5. Python Language Features
      • Highlight what's available
      • How to use it
      • When to use it
    6. How did you start Python?
      • Early Pythonistas – Today's Pythonistas:
      • Still not the first language
      • Who are these people?
      • Veni, vidi, vici
      • “Reads like pseudocode” - why not have a deeper look, this seems too good to be true
    7. Typical first Python
      • List comprehensions
      • names = [p.name for p in people if p.age>20]
      • Exception Handling: Easier to ask forgiveness than for permission
      • (famous “is string representing an integer?”)
      • “There's only one way to do it”
      • (in a python interpreter, “import this” for the Zen)
      • “Perfection is not when there is no more to add, but no more to take away” - Antoine de Saint-Exupery
      How nice!
    8. First problems, first pitfalls
      • Indentation for some hard to get used to (can lead to catastrophic bugs)
      • Importing: a) from mymodule import *
      • b) relative/absolute/site-packages
      • Too general 'try...except:”
      • Standard library all over the show (PEP8 (2001) under_score/CamelCase, xmlrpc client/server (were) effectively incompatible...)
      • What others can you think of?
    9. Minimalism is Appealing
      • Knife
      • Bow
      • Green light
      • Rambo is ready to roll – bring it on!
      • Ready to roll?
    10. Hang on...
        “Everything should be made as simple as possible, but not simpler.” - Albert Einstein
    11. Why people ignore features
        Sad but true: Solely for practical reasons!
      • “No need, can do everything without it” (Rambo)
      • Existing codebase not using it, retrofitting a bi***
      • Production server running old Python (Remember “True = 1”?)
      • Core problems taken care of by library or framework (one result: Pythonic vs. Zopish)
      • “Too busy coding”!
    12. Python Power Tools
        I had my power drill slung low on my toolbelt and I said,“Go ahead, honey. Break something.” - Tim Allen on the challenges of figuring out what to do with a new set of general-purpose tools
    13. NEXT
        Your vote!
    14. Tips & Tricks Often you need one little piece of information, and no one is to blame it's not there. Some things just... need some help
    15. Setting the Name of a Function If an outer function just returns an inner function (often a closure), the name of the returned function object is fixed, which can be confusing when the name is shown during introspection or debugging: >>> def make_adder(addend): … def adder(augend): return augend+addend … return adder … >>> plus100 = make_adder(100) >>> plus_23 = make_adder(23) >>> print plus100(1000), plus_23(1000) 1100 1023 >>> print plus100, plus_23 <function adder at 0x386530> <function adder at 0x3825f0>
    16. Python 2.4+ You can solve the problem by setting the __name_ attribute of the inner function before returning it: def make_adder(addend): def adder(augend): return augend+addend adder._name__ = 'add_%s' % (addend, ) With this change the output becomes more useful: >>> print plus100, plus_23 <function add_100 at 0x386530> <function add_23 at 0x3825f0>
    17. Python 2.3 Unfortunately, the __name__ attribute is read-only in this release. The same effect is achieved by constructing a new function object which differs from the other only in name: import new def make_adder(addend): def adder(augend): return augend+addend return new.function( adder.func_code, adder.func_globals, 'add_%s' % (addend,), adder.func_defaults, adder.func_closure )

    + danny.adairdanny.adair, 11 months ago

    custom

    579 views, 1 favs, 0 embeds more stats

    as presented at the NZPUG meeting in Auckland, Dece more

    More info about this document

    © All Rights Reserved

    Go to text version

    • Total Views 579
      • 579 on SlideShare
      • 0 from embeds
    • Comments 0
    • Favorites 1
    • Downloads 16
    Most viewed embeds

    more

    All embeds

    less

    Flagged as inappropriate Flag as inappropriate
    Flag as inappropriate

    Select your reason for flagging this presentation as inappropriate. If needed, use the feedback form to let us know more details.

    Cancel
    File a copyright complaint
    Having problems? Go to our helpdesk?

    Categories

    Groups / Events