SlideShare a Scribd company logo
 




Utan stödhjul och 
   motorsåg
Vad är Python?




● Ett dynamiskt typat språk
● Designat för enkelhet och tydlighet
It is the only language co-designed for the
  most advanced and the complete novice.

             [David Goodger]
Plattformar



● Python = CPython
● Jython (JVM)

● IronPython (.NET, Mono)

● PyPy (Python in Python)
Användningsområden

admin, byggen och driftsättning

webbapps, webbtjänster/+klienter

verktygsklister & GUIn (vanligt på linux)

dataskyffling/-konvertering/-analys
Scripta verktyg


Grafik (Gimp, Inkscape, Blender, ...), 
LibreOffice, ...

Spel (Battlefield 2+, Civ IV, EVE-Online, ...)

DVCS: Mercurial, Bazaar...
Användare
Python utan-stodhjul-motorsag
Python utan-stodhjul-motorsag
Python utan-stodhjul-motorsag
.. Sun, Microsoft, Canonical, O'Reilly, Lucasfilm, 
Nasa, Sourceforge, ...
Årets språk enligt Tiobe


      Bästa tillväxten

           2007
           2010
Moget


Utveckling & drift: doctest, nosetests, distribute,
pip, virtualenv, ...

Paket för allt: data, sysadmin, webb, grafik,
matematik, parallellism...
Design
Vad är viktigt?



Läsbarhet!

Namngivning!
Programming The 
Way Guido Indented It
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)
"In soviet russia, braces scope you"


from __future__ import braces


...
SyntaxError: not a chance
Effektivt


tokens = ['a', 'b', 'c', 'B', 'dd', 'C', 'DD']

similar = {}

for token in tokens:
    key = token.lower()
    similar.setdefault(key, []).append(token)
Lättanvänt


for key, tokens in similar.items():

    if len(tokens) > 1:
        print("Similar (like %s):" % key)

        for token in tokens:
            print(token)
Generella behållare



● list() == []
● dict() == {}

● tuple() == ()

● set()
Python är interaktivt



$ python
Python 2.7.1 [...]
Type "help", "copyright", "credits" or "license" for
more information.
>>>
>>>   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
Mekanik
"""
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
__protokoll__




Betyder används under ytan
Tydliga sammanhang



Börjar bukta när en dålig idé växer

●   state är explicit (self)
"""
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)
Allt är objekt



● primitiver
● collections

● funktioner, klasser

● moduler, paket
Ingen motorsåg..
"""Usage:
                      Closures
      >>> mkpasswd = salter("@secret#salt")
      >>> mkpasswd("qwerty")
      '4ef6056fb6f424f2e848705fd5e40602'
"""

from hashlib import md5

def salter(salt):

      def salted_encrypt(value):
          return md5(salt + value).hexdigest()

      return salted_encrypt


 
Funktionell @dekoration


from django.views.decorators.cache import cache_page

@cache_page(15 * 60)
def slashdot_index(request):
    result = resource_intensive_operation(request)
    return view_for(result)
Reduce boilerplate..


try:
    f = open('file1.txt')
    for line in f:
        print(line)

finally:
    f.close()
.. with contexts



with open('file1.txt') as f:

    for line in f:
        print(line)
Generators


def public_files(dirname):
    for fname in os.listdir(dirname):
        if not fname.startswith('.'):
            yield fname

for fname in public_files('.'):
    open(fname)
Projicera data
Maskinellt procedurell


publicfiles = []

for fname in os.listdir('.'):

    if not fname.startswith('.'):
        publicfiles.append(open(fname))
Tillståndslös spaghetti



publicfiles = map(lambda fname: open(fname),
                  filter(lambda fname:
                            not fname.startswith('.'),
                         os.listdir('.')))
List comprehensions



publicfiles = [open(fname)
               for fname in os.listdir('.')
               if not fname.startswith('.')]
Generator comprehensions



publicfiles = (open(fname)
               for fname in os.listdir('.')
               if not fname.startswith('.'))
process(open(fname) for fname in os.listdir('.')
        if not fname.startswith('.'))
Myter
"My way or the highway"
Sanningar
There should be one — and 
preferably only one — obvious 
         way to do it.
Although that way may not be 
 obvious at first unless you're 
            Dutch.
Python is humanism
Python ger dig




● Enkel men kraftfull kod
● Fokus på lösningen
Tack!
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."

More Related Content

PDF
The Browser Environment - A Systems Programmer's Perspective
Eleanor McHugh
 
PDF
Poker, packets, pipes and Python
Roger Barnes
 
PDF
"PostgreSQL and Python" Lightning Talk @EuroPython2014
Henning Jacobs
 
ODP
Programming Under Linux In Python
Marwan Osman
 
PDF
Pry at the Ruby Drink-up of Sophia, February 2012
rivierarb
 
KEY
Clojure入門
Naoyuki Kakuda
 
PDF
Happy Go Programming
Lin Yo-An
 
PDF
Palestra sobre Collections com Python
pugpe
 
The Browser Environment - A Systems Programmer's Perspective
Eleanor McHugh
 
Poker, packets, pipes and Python
Roger Barnes
 
"PostgreSQL and Python" Lightning Talk @EuroPython2014
Henning Jacobs
 
Programming Under Linux In Python
Marwan Osman
 
Pry at the Ruby Drink-up of Sophia, February 2012
rivierarb
 
Clojure入門
Naoyuki Kakuda
 
Happy Go Programming
Lin Yo-An
 
Palestra sobre Collections com Python
pugpe
 

What's hot (20)

PDF
Frege is a Haskell for the JVM
jwausle
 
PDF
Descobrindo a linguagem Perl
garux
 
PDF
Chrome拡張開発者のためのFirefox拡張開発
swdyh
 
PDF
Intro to Python
OSU Open Source Lab
 
PDF
Implementing virtual machines in go & c 2018 redux
Eleanor McHugh
 
ODP
NUMOSS 4th Week - Commandline Tutorial
Gagah Arifianto
 
PDF
Programming Lisp Clojure - 2장 : 클로저 둘러보기
JangHyuk You
 
PDF
(Fun clojure)
Timo Sulg
 
PDF
Communities - Perl edition (RioJS)
garux
 
PDF
Alta performance com Python
Bruno Barbosa
 
PPTX
Python basic
sewoo lee
 
PDF
PubNative Tracker
Andrew Djoga
 
KEY
An introduction to Ruby
Wes Oldenbeuving
 
PDF
Introduction of ES2015
Nakajima Shigeru
 
PDF
D-Talk: What's awesome about Ruby 2.x and Rails 4
Jan Berdajs
 
PDF
Introduction to jRuby
Adam Kalsey
 
PDF
Fertile Ground: The Roots of Clojure
Mike Fogus
 
ODP
Intro
Cosmin Poieana
 
PDF
Lập trình Python cơ bản
Nguyen Thi Lan Phuong
 
PDF
Happy Go Programming Part 1
Lin Yo-An
 
Frege is a Haskell for the JVM
jwausle
 
Descobrindo a linguagem Perl
garux
 
Chrome拡張開発者のためのFirefox拡張開発
swdyh
 
Intro to Python
OSU Open Source Lab
 
Implementing virtual machines in go & c 2018 redux
Eleanor McHugh
 
NUMOSS 4th Week - Commandline Tutorial
Gagah Arifianto
 
Programming Lisp Clojure - 2장 : 클로저 둘러보기
JangHyuk You
 
(Fun clojure)
Timo Sulg
 
Communities - Perl edition (RioJS)
garux
 
Alta performance com Python
Bruno Barbosa
 
Python basic
sewoo lee
 
PubNative Tracker
Andrew Djoga
 
An introduction to Ruby
Wes Oldenbeuving
 
Introduction of ES2015
Nakajima Shigeru
 
D-Talk: What's awesome about Ruby 2.x and Rails 4
Jan Berdajs
 
Introduction to jRuby
Adam Kalsey
 
Fertile Ground: The Roots of Clojure
Mike Fogus
 
Lập trình Python cơ bản
Nguyen Thi Lan Phuong
 
Happy Go Programming Part 1
Lin Yo-An
 
Ad

Similar to Python utan-stodhjul-motorsag (20)

PDF
Intro to Python
Daniel Greenfeld
 
PPTX
C# to python
Tess Ferrandez
 
PPTX
python beginner talk slide
jonycse
 
PDF
Python-GTK
Yuren Ju
 
PDF
PyParis 2017 / Camisole : A secure online sandbox to grade student - Antoine ...
Pôle Systematic Paris-Region
 
PDF
Learn 90% of Python in 90 Minutes
Matt Harrison
 
PDF
Python basic
Saifuddin Kaijar
 
PDF
Marrow: A Meta-Framework for Python 2.6+ and 3.1+
ConFoo
 
PDF
Python idiomatico
PyCon Italia
 
PDF
Pydiomatic
rik0
 
PDF
Introduction to python
Ahmed Salama
 
PDF
Python于Web 2.0网站的应用 - QCon Beijing 2010
Qiangning Hong
 
PDF
Becoming a Pythonist
Raji Engg
 
PDF
Ansible - Swiss Army Knife Orchestration
bcoca
 
PDF
Golang
Felipe Mamud
 
PDF
Music as data
John Vlachoyiannis
 
PDF
Geeks Anonymes - Le langage Go
Geeks Anonymes
 
PDF
Porting to Python 3
Lennart Regebro
 
PDF
A CTF Hackers Toolbox
Stefan
 
Intro to Python
Daniel Greenfeld
 
C# to python
Tess Ferrandez
 
python beginner talk slide
jonycse
 
Python-GTK
Yuren Ju
 
PyParis 2017 / Camisole : A secure online sandbox to grade student - Antoine ...
Pôle Systematic Paris-Region
 
Learn 90% of Python in 90 Minutes
Matt Harrison
 
Python basic
Saifuddin Kaijar
 
Marrow: A Meta-Framework for Python 2.6+ and 3.1+
ConFoo
 
Python idiomatico
PyCon Italia
 
Pydiomatic
rik0
 
Introduction to python
Ahmed Salama
 
Python于Web 2.0网站的应用 - QCon Beijing 2010
Qiangning Hong
 
Becoming a Pythonist
Raji Engg
 
Ansible - Swiss Army Knife Orchestration
bcoca
 
Golang
Felipe Mamud
 
Music as data
John Vlachoyiannis
 
Geeks Anonymes - Le langage Go
Geeks Anonymes
 
Porting to Python 3
Lennart Regebro
 
A CTF Hackers Toolbox
Stefan
 
Ad

More from niklal (6)

ODP
Something Specific and Simple
niklal
 
PDF
Länkad Data
niklal
 
PDF
(first '(Clojure.))
niklal
 
PDF
Webbens Arkitektur
niklal
 
PDF
Damn Fine CoffeeScript
niklal
 
PDF
Groovy Fly Through
niklal
 
Something Specific and Simple
niklal
 
Länkad Data
niklal
 
(first '(Clojure.))
niklal
 
Webbens Arkitektur
niklal
 
Damn Fine CoffeeScript
niklal
 
Groovy Fly Through
niklal
 

Recently uploaded (20)

PPTX
OA presentation.pptx OA presentation.pptx
pateldhruv002338
 
PDF
Unlocking the Future- AI Agents Meet Oracle Database 23ai - AIOUG Yatra 2025.pdf
Sandesh Rao
 
PDF
SparkLabs Primer on Artificial Intelligence 2025
SparkLabs Group
 
PDF
A Strategic Analysis of the MVNO Wave in Emerging Markets.pdf
IPLOOK Networks
 
PDF
Doc9.....................................
SofiaCollazos
 
PDF
Trying to figure out MCP by actually building an app from scratch with open s...
Julien SIMON
 
PDF
Security features in Dell, HP, and Lenovo PC systems: A research-based compar...
Principled Technologies
 
PDF
Tea4chat - another LLM Project by Kerem Atam
a0m0rajab1
 
PDF
Responsible AI and AI Ethics - By Sylvester Ebhonu
Sylvester Ebhonu
 
PDF
How Open Source Changed My Career by abdelrahman ismail
a0m0rajab1
 
PPTX
The-Ethical-Hackers-Imperative-Safeguarding-the-Digital-Frontier.pptx
sujalchauhan1305
 
PDF
Oracle AI Vector Search- Getting Started and what's new in 2025- AIOUG Yatra ...
Sandesh Rao
 
PDF
GDG Cloud Munich - Intro - Luiz Carneiro - #BuildWithAI - July - Abdel.pdf
Luiz Carneiro
 
PDF
MASTERDECK GRAPHSUMMIT SYDNEY (Public).pdf
Neo4j
 
PDF
Software Development Methodologies in 2025
KodekX
 
PPTX
The Future of AI & Machine Learning.pptx
pritsen4700
 
PDF
AI-Cloud-Business-Management-Platforms-The-Key-to-Efficiency-Growth.pdf
Artjoker Software Development Company
 
PPTX
Applied-Statistics-Mastering-Data-Driven-Decisions.pptx
parmaryashparmaryash
 
PPTX
AI in Daily Life: How Artificial Intelligence Helps Us Every Day
vanshrpatil7
 
PPTX
Agile Chennai 18-19 July 2025 Ideathon | AI Powered Microfinance Literacy Gui...
AgileNetwork
 
OA presentation.pptx OA presentation.pptx
pateldhruv002338
 
Unlocking the Future- AI Agents Meet Oracle Database 23ai - AIOUG Yatra 2025.pdf
Sandesh Rao
 
SparkLabs Primer on Artificial Intelligence 2025
SparkLabs Group
 
A Strategic Analysis of the MVNO Wave in Emerging Markets.pdf
IPLOOK Networks
 
Doc9.....................................
SofiaCollazos
 
Trying to figure out MCP by actually building an app from scratch with open s...
Julien SIMON
 
Security features in Dell, HP, and Lenovo PC systems: A research-based compar...
Principled Technologies
 
Tea4chat - another LLM Project by Kerem Atam
a0m0rajab1
 
Responsible AI and AI Ethics - By Sylvester Ebhonu
Sylvester Ebhonu
 
How Open Source Changed My Career by abdelrahman ismail
a0m0rajab1
 
The-Ethical-Hackers-Imperative-Safeguarding-the-Digital-Frontier.pptx
sujalchauhan1305
 
Oracle AI Vector Search- Getting Started and what's new in 2025- AIOUG Yatra ...
Sandesh Rao
 
GDG Cloud Munich - Intro - Luiz Carneiro - #BuildWithAI - July - Abdel.pdf
Luiz Carneiro
 
MASTERDECK GRAPHSUMMIT SYDNEY (Public).pdf
Neo4j
 
Software Development Methodologies in 2025
KodekX
 
The Future of AI & Machine Learning.pptx
pritsen4700
 
AI-Cloud-Business-Management-Platforms-The-Key-to-Efficiency-Growth.pdf
Artjoker Software Development Company
 
Applied-Statistics-Mastering-Data-Driven-Decisions.pptx
parmaryashparmaryash
 
AI in Daily Life: How Artificial Intelligence Helps Us Every Day
vanshrpatil7
 
Agile Chennai 18-19 July 2025 Ideathon | AI Powered Microfinance Literacy Gui...
AgileNetwork
 

Python utan-stodhjul-motorsag