Python utan-stodhjul-motorsag
Upcoming SlideShare
Loading in...5
×
 

Like this? Share it with your network

Share

Python utan-stodhjul-motorsag

on

  • 792 views

 

Statistics

Views

Total Views
792
Views on SlideShare
792
Embed Views
0

Actions

Likes
0
Downloads
1
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Python utan-stodhjul-motorsag Presentation Transcript

  • 1.  Utan stödhjul och  motorsåg
  • 2. Vad är Python?● Ett dynamiskt typat språk● Designat för enkelhet och tydlighet
  • 3. It is the only language co-designed for the most advanced and the complete novice. [David Goodger]
  • 4. Plattformar● Python = CPython● Jython (JVM)● IronPython (.NET, Mono)● PyPy (Python in Python)
  • 5. Användningsområdenadmin, byggen och driftsättningwebbapps, webbtjänster/+klienterverktygsklister & GUIn (vanligt på linux)dataskyffling/-konvertering/-analys
  • 6. Scripta verktygGrafik (Gimp, Inkscape, Blender, ...), LibreOffice, ...Spel (Battlefield 2+, Civ IV, EVE-Online, ...)DVCS: Mercurial, Bazaar...
  • 7. Användare
  • 8. .. Sun, Microsoft, Canonical, OReilly, Lucasfilm, Nasa, Sourceforge, ...
  • 9. Årets språk enligt Tiobe Bästa tillväxten 2007 2010
  • 10. MogetUtveckling & drift: doctest, nosetests, distribute,pip, virtualenv, ...Paket för allt: data, sysadmin, webb, grafik,matematik, parallellism...
  • 11. Design
  • 12. Vad är viktigt?Läsbarhet!Namngivning!
  • 13. Programming The Way Guido Indented It
  • 14. def to_roman(num): assert num > 0 and num < 4000 result = [] for d, r in NUMERALS: while num >= d: result.append(r) num -= d return .join(result)
  • 15. "In soviet russia, braces scope you"from __future__ import braces...SyntaxError: not a chance
  • 16. Effektivttokens = [a, b, c, B, dd, C, DD]similar = {}for token in tokens: key = token.lower() similar.setdefault(key, []).append(token)
  • 17. Lättanväntfor key, tokens in similar.items(): if len(tokens) > 1: print("Similar (like %s):" % key) for token in tokens: print(token)
  • 18. Generella behållare● list() == []● dict() == {}● tuple() == ()● set()
  • 19. Python är interaktivt$ pythonPython 2.7.1 [...]Type "help", "copyright", "credits" or "license" formore information.>>>
  • 20. >>> def add(a, b=1):... return a + b...>>> add(1)2>>> add(1, 2)3>>> add(2, b=3)5>>> add(b=3, a=2)5
  • 21. Mekanik
  • 22. """Usage: >>> usr = Path(/usr) >>> bin = usr.segment(local).segment(bin) >>> str(bin) /usr/local/bin"""class Path: def __init__(self, base): self.base = base def segment(self, name): return Path(self.base + / + name) def __str__(self): return self.base
  • 23. __protokoll__Betyder används under ytan
  • 24. Tydliga sammanhangBörjar bukta när en dålig idé växer● state är explicit (self)
  • 25. """Usage: >>> usr = Path(/usr) >>> bin = usr.segment(local).segment(bin) >>> str(bin) /usr/local/bin"""class Path(str): def segment(self, name): return Path(self + / + name)
  • 26. Allt är objekt● primitiver● collections● funktioner, klasser● moduler, paket
  • 27. Ingen motorsåg..
  • 28. """Usage: Closures >>> mkpasswd = salter("@secret#salt") >>> mkpasswd("qwerty") 4ef6056fb6f424f2e848705fd5e40602"""from hashlib import md5def salter(salt): def salted_encrypt(value): return md5(salt + value).hexdigest() return salted_encrypt 
  • 29. Funktionell @dekorationfrom django.views.decorators.cache import cache_page@cache_page(15 * 60)def slashdot_index(request): result = resource_intensive_operation(request) return view_for(result)
  • 30. Reduce boilerplate..try: f = open(file1.txt) for line in f: print(line)finally: f.close()
  • 31. .. with contextswith open(file1.txt) as f: for line in f: print(line)
  • 32. Generatorsdef public_files(dirname): for fname in os.listdir(dirname): if not fname.startswith(.): yield fnamefor fname in public_files(.): open(fname)
  • 33. Projicera data
  • 34. Maskinellt procedurellpublicfiles = []for fname in os.listdir(.): if not fname.startswith(.): publicfiles.append(open(fname))
  • 35. Tillståndslös spaghettipublicfiles = map(lambda fname: open(fname), filter(lambda fname: not fname.startswith(.), os.listdir(.)))
  • 36. List comprehensionspublicfiles = [open(fname) for fname in os.listdir(.) if not fname.startswith(.)]
  • 37. Generator comprehensionspublicfiles = (open(fname) for fname in os.listdir(.) if not fname.startswith(.))
  • 38. process(open(fname) for fname in os.listdir(.) if not fname.startswith(.))
  • 39. Myter
  • 40. "My way or the highway"
  • 41. Sanningar
  • 42. There should be one — and preferably only one — obvious  way to do it.
  • 43. Although that way may not be  obvious at first unless youre  Dutch.
  • 44. Python is humanism
  • 45. Python ger dig● Enkel men kraftfull kod● Fokus på lösningen
  • 46. Tack!
  • 47. Image Tributes (CC)Python, Google, YouTube, Spotify logos & Amazon Python Day Poster photo courtesy of respective organization.Night train"And so thy path shall be a track of light""Documents Reveal Django Pony, Caught In Tail Of Lies." / _why"inch by inch""Wasserglas""I am Jack, hear me lumber!""Bend me, Shape me, any way you want me."