Why I love Python!
By Johannes Lundberg
@johannesl
Founder & CEO of 46elks
The Interpreter
>>> 1+1
2
>>>
>>> s = 'hello'
>>> s.uppercase()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'str' object has no attribute
'uppercase'
Dynamic typing
i = 1234
hostname = '127.0.0.1'
python -i
python -i hello.py
>>> print i
1234
Great native types
i = 1234
name = 'Johannes Lundberg'
startups = [ 'Kundo', '46elks' ]
options = {
'port': 12345,
'logpath': '../debug.log'
}
Native types are objects
>>> startups.sort()
>>> startups
['46elks', 'Kundo']
s = 'Rxc3xa4kenskapsxc3xa5r'
print s.decode('utf-8')
Räkenskapsår
options.has_key('logpath')
name.split(' ')[-1]
(123).bit_length
dir()
>>> dir(’Pycon Sweden 2015’)
['capitalize', 'center', 'count', 'decode',
'encode', 'endswith', 'expandtabs', 'find',
'format', 'index', 'isalnum', 'isalpha',
'isdigit', 'islower', 'isspace', 'istitle',
'isupper', 'join', 'ljust', 'lower',
'lstrip', 'partition', 'replace', 'rfind',
'rindex', 'rjust', 'rpartition', 'rsplit',
'rstrip', 'split', 'splitlines',
'startswith', 'strip', 'swapcase', 'title',
'translate', 'upper', 'zfill']
Functions as first-class citizens
def writelog(s):
pass
if options.has_key('logpath'):
f = open(options['logpath'],'wb')
writelog = f.write
OOP is not mandatory
players = []
for line in open('players.txt'):
if not line.startswith('#'):
players.append( line.strip() )
Awesome standard libraries
import hashlib
import ftp
import urllib
s=urllib.urlopen('http://ph4.se/').read()
hashlib.sha256(s).hexdigest()
…
Works everywhere
scp hello.py ph4labs.com:.

Why I love Python!

  • 1.
    Why I lovePython! By Johannes Lundberg @johannesl Founder & CEO of 46elks
  • 2.
    The Interpreter >>> 1+1 2 >>> >>>s = 'hello' >>> s.uppercase() Traceback (most recent call last): File "<stdin>", line 1, in <module> AttributeError: 'str' object has no attribute 'uppercase'
  • 3.
    Dynamic typing i =1234 hostname = '127.0.0.1'
  • 4.
    python -i python -ihello.py >>> print i 1234
  • 5.
    Great native types i= 1234 name = 'Johannes Lundberg' startups = [ 'Kundo', '46elks' ] options = { 'port': 12345, 'logpath': '../debug.log' }
  • 6.
    Native types areobjects >>> startups.sort() >>> startups ['46elks', 'Kundo'] s = 'Rxc3xa4kenskapsxc3xa5r' print s.decode('utf-8') Räkenskapsår options.has_key('logpath') name.split(' ')[-1] (123).bit_length
  • 7.
    dir() >>> dir(’Pycon Sweden2015’) ['capitalize', 'center', 'count', 'decode', 'encode', 'endswith', 'expandtabs', 'find', 'format', 'index', 'isalnum', 'isalpha', 'isdigit', 'islower', 'isspace', 'istitle', 'isupper', 'join', 'ljust', 'lower', 'lstrip', 'partition', 'replace', 'rfind', 'rindex', 'rjust', 'rpartition', 'rsplit', 'rstrip', 'split', 'splitlines', 'startswith', 'strip', 'swapcase', 'title', 'translate', 'upper', 'zfill']
  • 8.
    Functions as first-classcitizens def writelog(s): pass if options.has_key('logpath'): f = open(options['logpath'],'wb') writelog = f.write
  • 9.
    OOP is notmandatory players = [] for line in open('players.txt'): if not line.startswith('#'): players.append( line.strip() )
  • 10.
    Awesome standard libraries importhashlib import ftp import urllib s=urllib.urlopen('http://ph4.se/').read() hashlib.sha256(s).hexdigest() …
  • 11.