Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Embrace Python

Embrace Python

Introduction level talk about Python held at ISDC Romania. Covers the history of Python, the "pythonic" philosophy, standard lib, web programming and some further learning resources.

stchris

June 29, 2012
Tweet

Other Decks in Programming

Transcript

  1. Who am I ? • Christian Stefanescu • http://0chris.com •

    [email protected] • twitter.com/0_chris • github.com/stchris • Software Developer at AcmePacket Berlin (http://www.acmepacket.com) • Team Lead – Infrastructure Team • Using Python for more than 5 years
  2. What we do with Python • Products: Palladion, PonD, FDP

    • Python everywhere! • Build system • Integration testing • Installer • Daemons • Clean-up and maintenance scripts • Internal web apps, IRC bot • Integrating Mercurial with other tools
  3. Scope of this talk • Python overview • What is

    it? • How can it help me? • How can it help my company? • Why would I use it? • Where can I use Python?
  4. Python is ... • … a strongly typed, dynamically typed

    language • … an interpreted language (with a byte- compiler) • … available for Linux/Unix, Mac OS X, Windows, JVM, CLR • … multi-paradigm: OO, imperative, functional
  5. Duck typing • „It walks like a duck and it

    quacks like a duck, so it must be a duck“ • Set of methods and attributes (and not inheritance) determines the context
  6. „Batteries included“ • Standard library is huge: base64, gzip, bzip,

    zip, tar, zlib, sockets, smtp/imap, url, http server, cookie, argument parser, confg fle parser, logging, serialization, csv fles, json, event scheduling, regex, struct, collections, path, tempfle, sqlite3, memory-mapped fles, in- memory fle-like objects, thread-like process lib, signals, subprocess, async i/o, xml handling, unittest, doctest, pdb (debugger), inspect, trace • REPL, IDLE
  7. PEPs • Python Enhancement Proposal • Design documents for new

    features • Include rationale, explanation, implementation suggestions • Openly discussed on python-dev ML • Approved by BDFL
  8. Style Guide for Python (PEP-8) • Code is read more

    often than written • Covers: • Tabs vs. Spaces • Whitespace in expressions, statements • Comments • Naming conventions
  9. The Zen of Python (PEP-20) • Beautiful is better than

    ugly. • Explicit is better than implicit. • Simple is better than complex. • Complex is better than complicated. • Flat is better than nested. • Sparse is better than dense. • Readability counts. • Special cases aren't special enough to break the rules. • Although practicality beats purity.
  10. The Zen of Python (PEP-20) • Errors should never pass

    silently. • Unless explicitly silenced. • In the face of ambiguity, refuse the temptation to guess. • There should be one-- and preferably only one --obvious way to do it. • Although that way may not be obvious at frst unless you're Dutch. • Now is better than never. • Although never is often better than *right* now. • If the implementation is hard to explain, it's a bad idea. • If the implementation is easy to explain, it may be a good idea. • Namespaces are one honking great idea -- let's do more of those!
  11. Data types • int, float • str, unicode • list,

    tuple • dict • boolean types: True, False
  12. Public / Protected / Private • „We are all consenting

    adults“ • Object.public • Object._protected • Object.__private
  13. • „I buy my eggs at the cheese shop“ •

    .egg • PyPi – the cheese shop • Pip • Setup.py
  14. State of packaging • distutils - built-in • setuptools –

    3rd party • distribute – successor to setuptools • packaging (distutils2) – not in 3.3
  15. Django • „The web framework for perfectionists with deadlines“ •

    opinionated • pluggable apps • Admin interface • ORM • templating • caching • i18n
  16. Flask • microframework • ~800 lines of code, ~1500 lines

    of tests • BYO ORM, templating, caching, … • suitable for heavy lifting
  17. Requests (HTTP for Humans) • stdlib support for http is

    broken • sane API • SSL • Cookies • Basic/digest/OAuth
  18. Twisted • Async programming framework • Network oriented • Protocol

    interfaces (clients, factories) • Plugin system
  19. Promising future developments • pypy • Python3 • Android •

    SL4A • python-android • Kivy (http://kivy.org)
  20. Learn • http://docs.python.org/tutorial/ • http://reddit.com/r/python (right sidebar) • http://www.doughellmann.com/PyMOTW/ •

    http://www.python-guide.org • Hitchhiker's guide to packaging: http://guide.python-distribute.org/
  21. Use • http://www.trypython.org/ • Type python in the command line

    • ipython, bpython • http://docs.python.org - API/module reference
  22. Stay in touch • Reddit.com/r/python • Planet.python.org • https://groups.google.com/group/python- romania

    • http://python.org/community/ • http://twitter.com/getpy • http://pythonweekly.com
  23. To me, Python is ... • … „executable pseudocode“ •

    … a swiss-army knife • … future-proof • … elegant • … compact