SlideShare una empresa de Scribd logo
1 de 120
Descargar para leer sin conexión
Daniel Greenfeld
pydanny.com / @pydanny
Daniel Greenfeld
Thinking Hard
About Python
Daniel Greenfeld
pydanny.com / @pydanny
@pydanny
Daniel Greenfeld
pydanny.com / @pydanny
http://2scoops.org
Danny: 128,546++
Audrey: 121,871++
Daniel Greenfeld
pydanny.com / @pydanny
What I
want you
to think
of me. One Cartwheel of Many Around the World
Daniel Greenfeld
pydanny.com / @pydanny
What
I’m
really
like. Myself at 13 in front of the Apple ][
Daniel Greenfeld
pydanny.com / @pydanny
Overview
Daniel Greenfeld
pydanny.com / @pydanny
Coding
into
Trouble
Daniel Greenfeld
pydanny.com / @pydanny
Controversy
Daniel Greenfeld
pydanny.com / @pydanny
Exceptions
Daniel Greenfeld
pydanny.com / @pydanny
Avoiding
Technical
Debt
Daniel Greenfeld
pydanny.com / @pydanny
...first section...
Coding
into
Trouble
Daniel Greenfeld
pydanny.com / @pydanny
a.k.a.
Super()
Troubles
Daniel Greenfeld
pydanny.com / @pydanny
Circle
The super method calls the
parent class, which is Circle
import math
class Circle(object):
def __init__(self, radius):
self.radius = radius
def area(self):
return self.radius ** 2 *math.pi
def __repr__(self):
return '{0} as area {1}'.format(
self.__class__.__name__, self.area()
)
class Donut(Circle):
def __init__(self, outer, inner):
super().__init__(outer)
self.inner = inner
def area(self):
outer, inner = self.radius, self.inner
return Circle(outer).area() - Circle(inner).area()
What if our inheritance
isn’t simple?
>>> Circle(10)
Circle as area
314.159265359
>>> Donut(10, 5)
235.619449019
Superclassing
is so easy!
Daniel Greenfeld
pydanny.com / @pydanny
Contention
The super() method can create ambiguity.
Daniel Greenfeld
pydanny.com / @pydanny
Example:
Django
Daniel Greenfeld
pydanny.com / @pydanny
Class Based Generic Views
• Composition
• Inheritance
• Subclassing
• Polymorphism
• Lots of other big words used to impress other developers, students, your boss, your
doctor, Capoiera mestre, dog, cat, friends, family, and other people who generally don’t care about such things.
Daniel Greenfeld
pydanny.com / @pydanny
However...
Daniel Greenfeld
pydanny.com / @pydanny
Things I don’t know:
The ancestor chain for
django.views.generic.edit.UpdateView
Daniel Greenfeld
pydanny.com / @pydanny
django.views.generic.edit.UpdateView
django.views.generic.detail.SingleObjectTemplateResponseMixin
django.views.generic.base.TemplateResponseMixin
django.views.generic.edit.BaseUpdateView
django.views.generic.edit.ModelFormMixin
django.views.generic.edit.FormMixin
django.views.generic.detail.SingleObjectMixin
django.views.generic.edit.ProcessFormView
django.views.generic.base.View
The ancestor chain for django.views.generic.edit.UpdateView:
Daniel Greenfeld
pydanny.com / @pydanny
def form_valid(self, form):
verb_form = verb_form_base(self.request.POST)
if verb_form.is_valid():
form.instance.verb_attributes = verb_form.cleaned_data
return super().form_valid(form)
A form_valid()
implementation
OMG Which form_valid()
am I calling?
Daniel Greenfeld
pydanny.com / @pydanny
class ActionUpdateView(
LoginRequiredMixin, # django-braces
ActionBaseView, # inherits from AuthorizedForProtocolMixin
AuthorizedforProtocolEditMixin, # Checks rights on edit views
VerbBaseView, # Gets one of 200+ verb forms
UpdateView): # django.views.generic.BaseView
def form_valid(self, form):
verb_form = verb_form_base(self.request.POST)
if verb_form.is_valid():
form.instance.verb_attributes = verb_form.cleaned_data
return super().form_valid(form)
A form_valid()
implementationOMG!
OMG!
OMG!
Daniel Greenfeld
pydanny.com / @pydanny
from actions.views import ActionUpdateView
for x in ActionUpdateView.mro():
print(x)
Ancestor Chain (MRO)
of ActionUpdateView
MRO = Method Resolution Order
Print the MRO
Daniel Greenfeld
pydanny.com / @pydanny
Ancestor Chain
(MRO)
<class 'actions.views.ActionUpdateView'>
<class 'braces.views.LoginRequiredMixin'>
<class 'actions.views.ActionBaseView'>
<class 'core.views.AuthorizedForProtocolMixin'>
<class 'core.views.AuthorizedforProtocolEditMixin'>
<class 'verbs.views.VerbBaseView'>
<class 'django.views.generic.edit.UpdateView'>
<class 'django.views.generic.detail.SingleObjectTemplateResponseMixin'>
<class 'django.views.generic.base.TemplateResponseMixin'>
<class 'django.views.generic.edit.BaseUpdateView'>
<class 'django.views.generic.edit.ModelFormMixin'>
<class 'django.views.generic.edit.FormMixin'>
<class 'django.views.generic.detail.SingleObjectMixin'>
<class 'django.views.generic.edit.ProcessFormView'>
<class 'django.views.generic.base.View'>
<type 'object'>
Daniel Greenfeld
pydanny.com / @pydanny
from actions.views import ActionUpdateView
for x in [x for x in ActionUpdateView.mro() if hasattr(x, "form_valid")]:
print(x)
Ancestor Chain (MRO)
of ActionUpdateView
Filter the MRO list to only include
classes with a form_valid() nethod
Daniel Greenfeld
pydanny.com / @pydanny
Ancestor Chain
(MRO) of
<class 'actions.views.ActionUpdateView'>
<class 'django.views.generic.edit.UpdateView'>
<class 'django.views.generic.edit.BaseUpdateView'>
<class 'django.views.generic.edit.ModelFormMixin'>
<class 'django.views.generic.edit.FormMixin'>
super’s chosen
form_valid() ancestor
Current class
Daniel Greenfeld
pydanny.com / @pydanny
Whew!
Daniel Greenfeld
pydanny.com / @pydanny
Safe!
Daniel Greenfeld
pydanny.com / @pydanny
If you’re not careful,
super can cause subtle
inheritance/MRO
problems.
Daniel Greenfeld
pydanny.com / @pydanny
• Hope that anyone else maintaining this
project isn’t going to kill me.
• Convert to a functional view.
• Explore better patterns.
Possible mitigations
for this view.
• return UpdateView.form_valid(self, form)
Daniel Greenfeld
pydanny.com / @pydanny
Write a easy-to-use
MRO inspector thingee
that identifies the parent
attributes/methods
specified by the coder.
TODO
Controversy
Daniel Greenfeld
pydanny.com / @pydanny
Special cases aren’t special enough to
break the rules.
Although practicality beats purity.*
* Zen of Python, lines 8 and 9
Daniel Greenfeld
pydanny.com / @pydanny
Zen of Python
$ python -c “import this”
The Zen of Python, by Tim Peters
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.
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 first 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!
PEP-0020
Daniel Greenfeld
pydanny.com / @pydanny
Special cases aren’t special enough to
break the rules.
Although practicality beats purity.*
* Zen of Python, lines 8 and 9
Daniel Greenfeld
pydanny.com / @pydanny
Web2py
Often honors Implicit over Explicit
Follows its own namespace pattern
Daniel Greenfeld
pydanny.com / @pydanny
# encoding: utf-8
# https://github.com/mdipierro/evote/blob/master/models/menu.py
# this file is released under public domain and
# you can use without limitations
response.title = 'Voting Service'
response.subtitle = None
## read more at http://dev.w3.org/html5/markup/meta.name.html
response.meta.author = 'Your Name <you@example.com>'
response.meta.description = 'a cool new app'
response.meta.keywords = 'web2py, python, framework'
response.meta.generator = 'Web2py Web Framework'
# snip more content that I cut in the name of brevity
Web2py code sample
Daniel Greenfeld
pydanny.com / @pydanny
# encoding: utf-8
# https://github.com/mdipierro/evote/blob/master/models/menu.py
# this file is released under public domain and
# you can use without limitations
response.title = 'Voting Service'
response.subtitle = None
## read more at http://dev.w3.org/html5/markup/meta.name.html
response.meta.author = 'Your Name <you@example.com>'
response.meta.description = 'a cool new app'
response.meta.keywords = 'web2py, python, framework'
response.meta.generator = 'Web2py Web Framework'
# snip more content that I cut in the name of brevity
Web2py code sample
I GET IT NOW
Europe taught me
why unicode is
important.
Daniel Greenfeld
pydanny.com / @pydanny
# encoding: utf-8
# https://github.com/mdipierro/evote/blob/master/models/menu.py
# this file is released under public domain and
# you can use without limitations
response.title = 'Voting Service'
response.subtitle = None
## read more at http://dev.w3.org/html5/markup/meta.name.html
response.meta.author = 'Your Name <you@example.com>'
response.meta.description = 'a cool new app'
response.meta.keywords = 'web2py, python, framework'
response.meta.generator = 'Web2py Web Framework'
# snip more content that I cut in the name of brevity
Web2py code sample
OK, Back to the talk...
Daniel Greenfeld
pydanny.com / @pydanny
Web2py code sample
# encoding: utf-8
# https://github.com/mdipierro/evote/blob/master/models/menu.py
# this file is released under public domain and
# you can use without limitations
response.title = 'Voting Service'
response.subtitle = None
## read more at http://dev.w3.org/html5/markup/meta.name.html
response.meta.author = 'Your Name <you@example.com>'
response.meta.description = 'a cool new app'
response.meta.keywords = 'web2py, python, framework'
response.meta.generator = 'Web2py Web Framework'
# snip more content that I cut in the name of brevity
Response object magically exists.
No import necessary
What can I expect in any location?What about namespace pollution?
Written by Massimo himself
Daniel Greenfeld
pydanny.com / @pydanny
Contention
• Explicit is better than implicit
• In the name of ambiguity, refuse the
temptation to guess
• Namespaces are one honking great idea --
let's do more of those!
Web2py violates these 3 koans:
* Zen of Python, lines 2, 12, 19
Daniel Greenfeld
pydanny.com / @pydanny
Controversy
Special cases aren’t special enough to break the rules.
Although practicality beats purity.*
* Zen of Python, lines 8, 9
Daniel Greenfeld
pydanny.com / @pydanny
Special cases aren’t special enough to break the rules.
Although practicality beats purity.*
Web2py contends:
* Zen of Python, lines 8, 9
Daniel Greenfeld
pydanny.com / @pydanny
Web2py contends:
• Implicit behaviors means Web2py is easier for
beginners to learn.
• The Web2py namespace pattern is easy to learn.
• For experienced developers, commonly repeated
imports are boilerplate.
Note:This is my interpretation of Web2py design considerations.
Personal side note:Web2py is very easy to install.
Daniel Greenfeld
pydanny.com / @pydanny
And that’s okay
Web2py will always
be contentious
Web2py argues practicality
in some very specific places.
Controversy
Special cases aren’t special enough to break the rules.
Although practicality beats purity.
Daniel Greenfeld
pydanny.com / @pydanny
Flask and its global Request object
http://bit.ly/flask-requests
A Little Magic
Goes a Long Way
Daniel Greenfeld
pydanny.com / @pydanny
Flask and its global Request object
http://bit.ly/flask-requests
A Little Magic
Goes a Long Way
Exceptions
Silent
Exceptions
are the
Devil
Daniel Greenfeld
pydanny.com / @pydanny
Exceptions
Errors should never pass silently.
Unless explicitly silenced.*
* Zen of Python, lines 10 and 11
Daniel Greenfeld
pydanny.com / @pydanny
djangopackages.com
• Once a day iterates across all
packages.
• Updates the metadata from:
• Github:
• Bitbucket
• PyPI
Daniel Greenfeld
pydanny.com / @pydanny
Django Packages
• Sometimes the APIs go down.
• Sometimes the APIs change.
• Sometimes projects get deleted.
• Sometimes the Internets fail
Problems
Catch and report exceptions!
Daniel Greenfeld
pydanny.com / @pydanny
Old package_updater.py
...
for package in Package.objects.all():
try:
package.fetch_metadata()
package.fetch_commits()
except socket_error, e:
text += "nFor '%s', threw a socket_error: %s" % 
(package.title, e)
continue
# snip lots of other exceptions
except Exception as e:
text += "nFor '%s', General Exception: %s" % 
(package.title, e)
continue
# email later
https://github.com/opencomparison/opencomparison/blob/master/package/management/commands/package_updater.py
http://bit.ly/Q8v9xk
Um...
Daniel Greenfeld
pydanny.com / @pydanny
What I was doing
>>> try:
... a = b
... except Exception as e:
... print(e)
...
name 'b' is not defined
What’s the
error type?!?
Where is my
stack trace?!?
(and it’s wrong)
Daniel Greenfeld
pydanny.com / @pydanny
What I wanted
>>> a = b
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'b' is not defined
Traceback
Error type
Error message
Daniel Greenfeld
pydanny.com / @pydanny
Exceptions
Errors should never pass silently.
Unless explicitly silenced.*
My code is
nearly silent
I’ve silenced things
for no good reason
* Zen of Python, lines 10 and 11
Daniel Greenfeld
pydanny.com / @pydanny
Getting what I want
>>> class CustomErrorHandler(Exception):
... def __init__(self, error):
... print(error)
... print(type(error))
...
>>> try:
... a=b
... except Exception as e:
... raise CustomErrorHandler(e)
...
name 'b' is not defined
Traceback (most recent call last):
File "<stdin>", line 4, in <module>
__main__.CustomErrorHandler
NameError
Traceback
Error message
For this example
print == log
No color because
it’s a print
statement
Error Type
Daniel Greenfeld
pydanny.com / @pydanny
PackageUpdaterException
Nice message
Full traceback
All errors
caught
class PackageUpdaterException(Exception):
def __init__(self, error, title):
log_message = "For {title}, {error_type}: {error}".format(
title=title,
error_type=type(error),
error=error
)
logging.error(log_message)
logging.exception(error)
for package in Package.objects.all():
try:
try:
package.fetch_metadata()
package.fetch_commits()
except Exception as e:
raise PackageUpdaterException(e, package.title)
except PackageUpdaterException:
continue
Loop forward
Daniel Greenfeld
pydanny.com / @pydanny
Exceptions
Errors should never pass silently.
Unless explicitly silenced.
My code is
nearly silent
I’ve silenced things
for no good reason
Daniel Greenfeld
pydanny.com / @pydanny
Exceptions
Errors should never pass silently.
Unless explicitly silenced.
Daniel Greenfeld
pydanny.com / @pydanny
Next
up...
The Dutch Way
Daniel Greenfeld
pydanny.com / @pydanny
Decorators
@memoize
def allcaps(string):
return string.upper()
def allcaps(string):
return string.upper()
allcaps = memoize(allcaps)
>
Decorators are
easy to explain!
“A decorator is a function that returns a function.”
Daniel Greenfeld
pydanny.com / @pydanny
I am Zen
Decorators == Zen of Python
Daniel Greenfeld
pydanny.com / @pydanny
Until...
Daniel Greenfeld
pydanny.com / @pydanny
I am not Zen
I need to write a decorator.
Daniel Greenfeld
pydanny.com / @pydanny
You try to shoot yourself in the foot, only
to realize there’s no need, since Guido
thoughtfully shot you in the foot years ago.
-- Nick Mathewson, comp.lang.python
http://starship.python.net/~mwh/quotes.html
Ouch
Daniel Greenfeld
pydanny.com / @pydanny
Decorators
@memoize
def allcaps(string):
return string.upper()
def allcaps(string):
return string.upper()
allcaps = memoize(allcaps)
>
Decorators are
easy to explain!
“A decorator is a function that returns a function.”
Daniel Greenfeld
pydanny.com / @pydanny
Decorator Template
http://pydanny-event-notes.readthedocs.org/en/latest/SCALE10x/python-decorators.html#decorator-template
def decorator(function_to_decorate):
def wrapper(*args, **kwargs):
# do something before invoation
result = func_to_decorate(*args, **kwargs)
# do something after
return result
# update wrapper.__doc__ and .func_name
# or functools.wraps
return wrapper
Result is returned when
the wrapper is done
When decorated function is
called decorator returns wrapper
Wrapper function
does things before
and after the function
is called here.
Wrapper function
does things before
and after the function
is called here.
Daniel Greenfeld
pydanny.com / @pydanny
The Dutch Way
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.*
* Zen of Python, lines 13 and 14
Daniel Greenfeld
pydanny.com / @pydanny
Decorator
implementation
def memoize(func):
cache = {}
def memoized(*args):
if args in cache:
return cache[args]
result = cache[args] = func(*args)
return result
return memoized
@memoize
def allcaps(string):
return string.upper()
Return function
Return value
set cache
Return value if
args in cache
Datastore
Daniel Greenfeld
pydanny.com / @pydanny
Whew.
Daniel Greenfeld
pydanny.com / @pydanny
What about decorators
that accept arguments?
Daniel Greenfeld
pydanny.com / @pydanny
Oh No.
Daniel Greenfeld
pydanny.com / @pydanny
Explaining this is
Hard.
That’s because we create a decorator that creates a
parameterized function to wrap the function.
Daniel Greenfeld
pydanny.com / @pydanny
multiplier decorator
def multiplier(multiple):
def decorator(function):
def wrapper(*args, **kwargs):
return function(*args, **kwargs) * multiple
return wrapper
return decorator
@multiplier(5)
def allcaps(string):
return string.upper()
Multiplier function
sets the state for
the multiple
argument
When decorated function is
called the decorator function
returns the wrapper function
Result is returned when the
wrapper is done.
Wrapper function does:
What am I supposed
to highlight?
Daniel Greenfeld
pydanny.com / @pydanny
Whew
Daniel Greenfeld
pydanny.com / @pydanny
Oh No.
Daniel Greenfeld
pydanny.com / @pydanny
Not Done Yet!
Daniel Greenfeld
pydanny.com / @pydanny
authentication
decorator
@authorization('admin')
def do_admin_thing(user):
# do something administrative
return user
import functools
def authorization(roles):
def decorator(function):
@functools.wraps(function)
def wrapper(*args, **kwargs):
check_roles(user, roles)
return function(*args, **kwargs)
return wrapper
return decorator
Don’t forget functools!
Daniel Greenfeld
pydanny.com / @pydanny
Whew
Daniel Greenfeld
pydanny.com / @pydanny
Really.
Daniel Greenfeld
pydanny.com / @pydanny
I’m not doing
class decorators.
Daniel Greenfeld
pydanny.com / @pydanny
It is not easy
to explain how
to write decorators.
Daniel Greenfeld
pydanny.com / @pydanny
Contention
While Using
decorators is
Zen...
Daniel Greenfeld
pydanny.com / @pydanny
Contention
Writing
Decorators
is Not.
Daniel Greenfeld
pydanny.com / @pydanny
Deep Thought
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.
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.
Although practicality beats purity.
Decorators are
easy to explain!
Decorators are
hard to explain!
Daniel Greenfeld
pydanny.com / @pydanny
Use the
decorator library
https://pypi.python.org/pypi/decorator
Avoiding
Technical
Debt
Part I
Daniel Greenfeld
pydanny.com / @pydanny
Getting it done
vs.
Technical debt
Now is better than never.
Although never is often better than *right* now.
* Zen of Python, lines 15 and 16
Daniel Greenfeld
pydanny.com / @pydanny
• Tests
• Documentation
Some things take time
Risk: Deploying broken code
Risk: problems upgrading dependencies
Risk: Forgetting install/deploy
Risk: Multiple coding standards
(Risks of skipping them)
Daniel Greenfeld
pydanny.com / @pydanny
Easy Test Patterns
• Always make sure your test harness can
run
• Try using tests instead of the shell/repl.
• After the first deadline, reject any incoming
code that drops coverage.
• Use coverage.py
For developers racing to meet deadlines:
Daniel Greenfeld
pydanny.com / @pydanny
Must-have
Documentation
• Installation/Deployment procedures
• Coding standards
• How to run tests
• Version (including __version__)
Daniel Greenfeld
pydanny.com / @pydanny
Easy Test Patterns
• Always make sure your test harness can run
• Try using tests instead of the shell/repl.
• Reject any incoming code that drops coverage.
• Use coverage.py
Daniel Greenfeld
pydanny.com / @pydanny
Getting technical
again...
Avoiding
Technical
Debt
Part II
Daniel Greenfeld
pydanny.com / @pydanny
Namespaces
• Extremely powerful
• Useful
• Precise
import re
import os
from twisted.internet import protocol, reactor
from django import forms
from myproject import utils
Daniel Greenfeld
pydanny.com / @pydanny
import * makes
development faster[1]
• Extremely powerful
• Useful
• Imports everything at once! [2]
from re import *
from os import *
from twisted import *
from django.forms import *
from myproject.utils import *
[1]Warning: import * can be dangerous
[2]Warning: import * can be dangerous
Daniel Greenfeld
pydanny.com / @pydanny
Comparing two modules
def compare(mod1, mod2):
title = 'nComparing {0}, {1}:'.format(
mod1.__name__,
mod2.__name__
)
print(title)
for x in dir(mod1):
for y in dir(mod2):
if x == y and not x.startswith('_'):
print("* " + x)
Daniel Greenfeld
pydanny.com / @pydanny
>>> re.sys == os.sys
True
>>> re.error == os.error
False
Comparing two modules
>>> import re
>>> import os
>>> compare(os, re)
Comparing os, re:
* sys
* error
import * can get you into trouble
from re import *
from os import *
Daniel Greenfeld
pydanny.com / @pydanny
Breaking built-ins
def compare_builtins(mod1):
print("nComparing {0} to builtins:".format(mod1.__name__))
for x in dir(mod1):
for y in dir(globals()['__builtins__']):
if x == y and not x.startswith('_'):
print("* GLOBAL: {0}".format(x))
Checks to see if a module has items
that match any Python built-in.
Daniel Greenfeld
pydanny.com / @pydanny
Breaking built-ins
>>> compare_builtins(re)
Comparing re to builtins:
* GLOBAL: compile
>>> compare_builtins(os)
Comparing os to builtins:
* GLOBAL: open
from re import *
from os import *
Breaks compile() built-in.
Annoying but
infrequent problem.
Breaks open() built-in.
This can drive you crazy.
Compare ‘re’ Compare ‘os’
Daniel Greenfeld
pydanny.com / @pydanny
The open() story
from os import *after
before
Breaks
all
the
things!
Help on built-in function open in module __builtin__:
open(...)
open(name[, mode[, buffering]]) -> file object
Open a file using the file() type, returns a file object. This is the
preferred way to open a file. See file.__doc__ for further information.
Help on built-in function open in module posix:
open(...)
open(filename, flag [, mode=0777]) -> fd
Open a file (for low level IO).
Daniel Greenfeld
pydanny.com / @pydanny
Beginner pro-tip
Be careful of tutorials that use import *.
Daniel Greenfeld
pydanny.com / @pydanny
Contention
import * is not for beginners.
import * is people who really know Python.
__all__ = ["echo", "surround", "reverse"]
Summary
Daniel Greenfeld
pydanny.com / @pydanny
Stay
this
person
Myself at 13 in front of the Apple ][
Daniel Greenfeld
pydanny.com / @pydanny
Admit What
You Don't
Know
Daniel Greenfeld
pydanny.com / @pydanny
Stay out of
your comfort
Zone
Daniel Greenfeld
pydanny.com / @pydanny
Grow
Daniel Greenfeld
pydanny.com / @pydanny
What I Want To Know
• Twisted
• Numpy
• SciPy
• Tulip
• C
• Etc.
Daniel Greenfeld
pydanny.com / @pydanny
If I continue
to Learn
Daniel Greenfeld
pydanny.com / @pydanny
I Get
To Be
This
Person
Daniel Greenfeld
pydanny.com / @pydanny
Think
Hard
Daniel Greenfeld
pydanny.com / @pydanny
Thank you
• Armin Ronacher
• nephila.it
• Richard Jones
• Raymond Hettiger
• EuroPython
• PyKonik
• Łukasz Langa
• Tomasz Paczkowski
Daniel Greenfeld
pydanny.com / @pydanny
Thank you
• Matt Harrison
• Ola Sendecka
• Kenneth Love
• Lennart Regebro
• Paul Hildebrandt
• Audrey Roy
Daniel Greenfeld
pydanny.com / @pydanny
One More
Thing...
Daniel Greenfeld
pydanny.com / @pydanny
Finis
Daniel Greenfeld
pydanny.com / @pydanny
Q & A

Más contenido relacionado

La actualidad más candente

Realtime Apps with Django
Realtime Apps with DjangoRealtime Apps with Django
Realtime Apps with DjangoRenyi Khor
 
Advanced Django Forms Usage
Advanced Django Forms UsageAdvanced Django Forms Usage
Advanced Django Forms UsageDaniel Greenfeld
 
BarCamb Connotea by Ian Mulvany
BarCamb Connotea by Ian MulvanyBarCamb Connotea by Ian Mulvany
BarCamb Connotea by Ian MulvanyIan Mulvany
 
Python教程 / Python tutorial
Python教程 / Python tutorialPython教程 / Python tutorial
Python教程 / Python tutorialee0703
 
Python Programming Language | Python Classes | Python Tutorial | Python Train...
Python Programming Language | Python Classes | Python Tutorial | Python Train...Python Programming Language | Python Classes | Python Tutorial | Python Train...
Python Programming Language | Python Classes | Python Tutorial | Python Train...Edureka!
 
Random And Dynamic Images Using Python Cgi
Random And Dynamic Images Using Python CgiRandom And Dynamic Images Using Python Cgi
Random And Dynamic Images Using Python CgiAkramWaseem
 
Writing Fast Code (JP) - PyCon JP 2015
Writing Fast Code (JP) - PyCon JP 2015Writing Fast Code (JP) - PyCon JP 2015
Writing Fast Code (JP) - PyCon JP 2015Younggun Kim
 
Python Tutorial | Python Tutorial for Beginners | Python Training | Edureka
Python Tutorial | Python Tutorial for Beginners | Python Training | EdurekaPython Tutorial | Python Tutorial for Beginners | Python Training | Edureka
Python Tutorial | Python Tutorial for Beginners | Python Training | EdurekaEdureka!
 
PHP Annotations: They exist! - JetBrains Webinar
 PHP Annotations: They exist! - JetBrains Webinar PHP Annotations: They exist! - JetBrains Webinar
PHP Annotations: They exist! - JetBrains WebinarRafael Dohms
 
What is Python? (Silicon Valley CodeCamp 2014)
What is Python? (Silicon Valley CodeCamp 2014)What is Python? (Silicon Valley CodeCamp 2014)
What is Python? (Silicon Valley CodeCamp 2014)wesley chun
 

La actualidad más candente (13)

Introduce Django
Introduce DjangoIntroduce Django
Introduce Django
 
Dynamic Python
Dynamic PythonDynamic Python
Dynamic Python
 
Realtime Apps with Django
Realtime Apps with DjangoRealtime Apps with Django
Realtime Apps with Django
 
Advanced Django Forms Usage
Advanced Django Forms UsageAdvanced Django Forms Usage
Advanced Django Forms Usage
 
BarCamb Connotea by Ian Mulvany
BarCamb Connotea by Ian MulvanyBarCamb Connotea by Ian Mulvany
BarCamb Connotea by Ian Mulvany
 
Python教程 / Python tutorial
Python教程 / Python tutorialPython教程 / Python tutorial
Python教程 / Python tutorial
 
Python Programming Language | Python Classes | Python Tutorial | Python Train...
Python Programming Language | Python Classes | Python Tutorial | Python Train...Python Programming Language | Python Classes | Python Tutorial | Python Train...
Python Programming Language | Python Classes | Python Tutorial | Python Train...
 
Random And Dynamic Images Using Python Cgi
Random And Dynamic Images Using Python CgiRandom And Dynamic Images Using Python Cgi
Random And Dynamic Images Using Python Cgi
 
Writing Fast Code (JP) - PyCon JP 2015
Writing Fast Code (JP) - PyCon JP 2015Writing Fast Code (JP) - PyCon JP 2015
Writing Fast Code (JP) - PyCon JP 2015
 
Python Tutorial | Python Tutorial for Beginners | Python Training | Edureka
Python Tutorial | Python Tutorial for Beginners | Python Training | EdurekaPython Tutorial | Python Tutorial for Beginners | Python Training | Edureka
Python Tutorial | Python Tutorial for Beginners | Python Training | Edureka
 
What is Python?
What is Python?What is Python?
What is Python?
 
PHP Annotations: They exist! - JetBrains Webinar
 PHP Annotations: They exist! - JetBrains Webinar PHP Annotations: They exist! - JetBrains Webinar
PHP Annotations: They exist! - JetBrains Webinar
 
What is Python? (Silicon Valley CodeCamp 2014)
What is Python? (Silicon Valley CodeCamp 2014)What is Python? (Silicon Valley CodeCamp 2014)
What is Python? (Silicon Valley CodeCamp 2014)
 

Destacado

Python 101: Python for Absolute Beginners (PyTexas 2014)
Python 101: Python for Absolute Beginners (PyTexas 2014)Python 101: Python for Absolute Beginners (PyTexas 2014)
Python 101: Python for Absolute Beginners (PyTexas 2014)Paige Bailey
 
Advance OOP concepts in Python
Advance OOP concepts in PythonAdvance OOP concepts in Python
Advance OOP concepts in PythonSujith Kumar
 
Learn 90% of Python in 90 Minutes
Learn 90% of Python in 90 MinutesLearn 90% of Python in 90 Minutes
Learn 90% of Python in 90 MinutesMatt Harrison
 
Introduction to Python
Introduction to PythonIntroduction to Python
Introduction to PythonNowell Strite
 
Advanced Python : Static and Class Methods
Advanced Python : Static and Class Methods Advanced Python : Static and Class Methods
Advanced Python : Static and Class Methods Bhanwar Singh Meena
 
Python Programming Language
Python Programming LanguagePython Programming Language
Python Programming LanguageLaxman Puri
 
Introduction to python for Beginners
Introduction to python for Beginners Introduction to python for Beginners
Introduction to python for Beginners Sujith Kumar
 
Introduction to Python
Introduction to Python Introduction to Python
Introduction to Python amiable_indian
 
Basics of Object Oriented Programming in Python
Basics of Object Oriented Programming in PythonBasics of Object Oriented Programming in Python
Basics of Object Oriented Programming in PythonSujith Kumar
 
Object-oriented Programming in Python
Object-oriented Programming in PythonObject-oriented Programming in Python
Object-oriented Programming in PythonJuan-Manuel Gimeno
 
Python PPT
Python PPTPython PPT
Python PPTEdureka!
 
PyCon Philippines 2012 Keynote
PyCon Philippines 2012 KeynotePyCon Philippines 2012 Keynote
PyCon Philippines 2012 KeynoteDaniel Greenfeld
 
Intro to Data Visualizations
Intro to Data VisualizationsIntro to Data Visualizations
Intro to Data VisualizationsDaniel Greenfeld
 
Python Anti patterns / tips / tricks
Python Anti patterns / tips / tricksPython Anti patterns / tips / tricks
Python Anti patterns / tips / tricksrikbyte
 
Python trading
Python tradingPython trading
Python tradingAlicia G
 
Finanças Quantitativas com python
Finanças Quantitativas com pythonFinanças Quantitativas com python
Finanças Quantitativas com pythonWilson Freitas
 
Regular expressions in Python
Regular expressions in PythonRegular expressions in Python
Regular expressions in PythonSujith Kumar
 

Destacado (20)

Python 101: Python for Absolute Beginners (PyTexas 2014)
Python 101: Python for Absolute Beginners (PyTexas 2014)Python 101: Python for Absolute Beginners (PyTexas 2014)
Python 101: Python for Absolute Beginners (PyTexas 2014)
 
Advance OOP concepts in Python
Advance OOP concepts in PythonAdvance OOP concepts in Python
Advance OOP concepts in Python
 
Learn 90% of Python in 90 Minutes
Learn 90% of Python in 90 MinutesLearn 90% of Python in 90 Minutes
Learn 90% of Python in 90 Minutes
 
Introduction to Python
Introduction to PythonIntroduction to Python
Introduction to Python
 
Advanced Python : Static and Class Methods
Advanced Python : Static and Class Methods Advanced Python : Static and Class Methods
Advanced Python : Static and Class Methods
 
Python Programming Language
Python Programming LanguagePython Programming Language
Python Programming Language
 
Introduction to python for Beginners
Introduction to python for Beginners Introduction to python for Beginners
Introduction to python for Beginners
 
Introduction to Python
Introduction to Python Introduction to Python
Introduction to Python
 
Basics of Object Oriented Programming in Python
Basics of Object Oriented Programming in PythonBasics of Object Oriented Programming in Python
Basics of Object Oriented Programming in Python
 
Object-oriented Programming in Python
Object-oriented Programming in PythonObject-oriented Programming in Python
Object-oriented Programming in Python
 
Python PPT
Python PPTPython PPT
Python PPT
 
Python Presentation
Python PresentationPython Presentation
Python Presentation
 
PyCon Philippines 2012 Keynote
PyCon Philippines 2012 KeynotePyCon Philippines 2012 Keynote
PyCon Philippines 2012 Keynote
 
Intro to Data Visualizations
Intro to Data VisualizationsIntro to Data Visualizations
Intro to Data Visualizations
 
Intro
IntroIntro
Intro
 
The One Way
The One WayThe One Way
The One Way
 
Python Anti patterns / tips / tricks
Python Anti patterns / tips / tricksPython Anti patterns / tips / tricks
Python Anti patterns / tips / tricks
 
Python trading
Python tradingPython trading
Python trading
 
Finanças Quantitativas com python
Finanças Quantitativas com pythonFinanças Quantitativas com python
Finanças Quantitativas com python
 
Regular expressions in Python
Regular expressions in PythonRegular expressions in Python
Regular expressions in Python
 

Similar a Thinking hard about_python

Red Hat Certified Engineer (RHCE) EX294 Exam Questions
Red Hat Certified Engineer (RHCE) EX294 Exam QuestionsRed Hat Certified Engineer (RHCE) EX294 Exam Questions
Red Hat Certified Engineer (RHCE) EX294 Exam QuestionsStudy Material
 
Why Drupal Should Be More Like WordPress
Why Drupal Should Be More Like WordPressWhy Drupal Should Be More Like WordPress
Why Drupal Should Be More Like WordPressJen Lampton
 
Django tutorial
Django tutorialDjango tutorial
Django tutorialKsd Che
 
Integration Testing With Cucumber How To Test Anything J A O O 2009
Integration Testing With  Cucumber    How To Test Anything    J A O O 2009Integration Testing With  Cucumber    How To Test Anything    J A O O 2009
Integration Testing With Cucumber How To Test Anything J A O O 2009Dr Nic Williams
 
JDD2015: Forgetting Java: Why Java Should Die in Flames and Take its Develope...
JDD2015: Forgetting Java: Why Java Should Die in Flames and Take its Develope...JDD2015: Forgetting Java: Why Java Should Die in Flames and Take its Develope...
JDD2015: Forgetting Java: Why Java Should Die in Flames and Take its Develope...PROIDEA
 
Iz Pack
Iz PackIz Pack
Iz PackInria
 
Growing pains - PosKeyErrors and other malaises
Growing pains - PosKeyErrors and other malaisesGrowing pains - PosKeyErrors and other malaises
Growing pains - PosKeyErrors and other malaisesPhilip Bauer
 
Big guns for small guys (reloaded)
Big guns for small guys (reloaded)Big guns for small guys (reloaded)
Big guns for small guys (reloaded)Jorge López-Lago
 
10 Ways To Improve Your Code( Neal Ford)
10  Ways To  Improve  Your  Code( Neal  Ford)10  Ways To  Improve  Your  Code( Neal  Ford)
10 Ways To Improve Your Code( Neal Ford)guestebde
 
Android design patterns
Android design patternsAndroid design patterns
Android design patternsVitali Pekelis
 
Introduction to BDD (Behavior-Driven Development)
Introduction to BDD (Behavior-Driven Development)Introduction to BDD (Behavior-Driven Development)
Introduction to BDD (Behavior-Driven Development)Juan Rodríguez
 
Building Websites of the Future With Drupal 7
Building Websites of the Future With Drupal 7Building Websites of the Future With Drupal 7
Building Websites of the Future With Drupal 7Jay Epstein
 
Building Websites of the Future With Drupal 7
Building Websites of the Future With Drupal 7Building Websites of the Future With Drupal 7
Building Websites of the Future With Drupal 7Jay Epstein
 
Using MongoDB and a Relational Database at MongoDB Day
Using MongoDB and a Relational Database at MongoDB DayUsing MongoDB and a Relational Database at MongoDB Day
Using MongoDB and a Relational Database at MongoDB Dayhayesdavis
 
Get involved in Open Source
Get involved in Open SourceGet involved in Open Source
Get involved in Open SourceJoe Brinkman
 

Similar a Thinking hard about_python (20)

Designing Testable Software
Designing Testable SoftwareDesigning Testable Software
Designing Testable Software
 
Red Hat Certified Engineer (RHCE) EX294 Exam Questions
Red Hat Certified Engineer (RHCE) EX294 Exam QuestionsRed Hat Certified Engineer (RHCE) EX294 Exam Questions
Red Hat Certified Engineer (RHCE) EX294 Exam Questions
 
Why Drupal Should Be More Like WordPress
Why Drupal Should Be More Like WordPressWhy Drupal Should Be More Like WordPress
Why Drupal Should Be More Like WordPress
 
Django tutorial
Django tutorialDjango tutorial
Django tutorial
 
Integration Testing With Cucumber How To Test Anything J A O O 2009
Integration Testing With  Cucumber    How To Test Anything    J A O O 2009Integration Testing With  Cucumber    How To Test Anything    J A O O 2009
Integration Testing With Cucumber How To Test Anything J A O O 2009
 
JDD2015: Forgetting Java: Why Java Should Die in Flames and Take its Develope...
JDD2015: Forgetting Java: Why Java Should Die in Flames and Take its Develope...JDD2015: Forgetting Java: Why Java Should Die in Flames and Take its Develope...
JDD2015: Forgetting Java: Why Java Should Die in Flames and Take its Develope...
 
Iz Pack
Iz PackIz Pack
Iz Pack
 
Growing pains - PosKeyErrors and other malaises
Growing pains - PosKeyErrors and other malaisesGrowing pains - PosKeyErrors and other malaises
Growing pains - PosKeyErrors and other malaises
 
The Modlet Pattern
The Modlet PatternThe Modlet Pattern
The Modlet Pattern
 
Reusable Apps
Reusable AppsReusable Apps
Reusable Apps
 
Drupal Front End PHP
Drupal Front End PHPDrupal Front End PHP
Drupal Front End PHP
 
Big guns for small guys (reloaded)
Big guns for small guys (reloaded)Big guns for small guys (reloaded)
Big guns for small guys (reloaded)
 
10 Ways To Improve Your Code( Neal Ford)
10  Ways To  Improve  Your  Code( Neal  Ford)10  Ways To  Improve  Your  Code( Neal  Ford)
10 Ways To Improve Your Code( Neal Ford)
 
Android design patterns
Android design patternsAndroid design patterns
Android design patterns
 
Introduction to BDD (Behavior-Driven Development)
Introduction to BDD (Behavior-Driven Development)Introduction to BDD (Behavior-Driven Development)
Introduction to BDD (Behavior-Driven Development)
 
Building Websites of the Future With Drupal 7
Building Websites of the Future With Drupal 7Building Websites of the Future With Drupal 7
Building Websites of the Future With Drupal 7
 
Building Websites of the Future With Drupal 7
Building Websites of the Future With Drupal 7Building Websites of the Future With Drupal 7
Building Websites of the Future With Drupal 7
 
Using MongoDB and a Relational Database at MongoDB Day
Using MongoDB and a Relational Database at MongoDB DayUsing MongoDB and a Relational Database at MongoDB Day
Using MongoDB and a Relational Database at MongoDB Day
 
10 Ways To Improve Your Code
10 Ways To Improve Your Code10 Ways To Improve Your Code
10 Ways To Improve Your Code
 
Get involved in Open Source
Get involved in Open SourceGet involved in Open Source
Get involved in Open Source
 

Más de Daniel Greenfeld

Más de Daniel Greenfeld (12)

10 more-things-you-can-do-with-python
10 more-things-you-can-do-with-python10 more-things-you-can-do-with-python
10 more-things-you-can-do-with-python
 
From NASA to Startups to Big Commerce
From NASA to Startups to Big CommerceFrom NASA to Startups to Big Commerce
From NASA to Startups to Big Commerce
 
Round pegs and square holes
Round pegs and square holesRound pegs and square holes
Round pegs and square holes
 
Django Worst Practices
Django Worst PracticesDjango Worst Practices
Django Worst Practices
 
How to sell django panel
How to sell django panelHow to sell django panel
How to sell django panel
 
Pinax Long Tutorial Slides
Pinax Long Tutorial SlidesPinax Long Tutorial Slides
Pinax Long Tutorial Slides
 
Testing In Django
Testing In DjangoTesting In Django
Testing In Django
 
Django Uni-Form
Django Uni-FormDjango Uni-Form
Django Uni-Form
 
Nova Django
Nova DjangoNova Django
Nova Django
 
Pinax Introduction
Pinax IntroductionPinax Introduction
Pinax Introduction
 
Why Django
Why DjangoWhy Django
Why Django
 
Pinax Tutorial 09/09/09
Pinax Tutorial 09/09/09Pinax Tutorial 09/09/09
Pinax Tutorial 09/09/09
 

Último

Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhisoniya singh
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 

Último (20)

Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 

Thinking hard about_python

  • 1. Daniel Greenfeld pydanny.com / @pydanny Daniel Greenfeld Thinking Hard About Python
  • 2. Daniel Greenfeld pydanny.com / @pydanny @pydanny
  • 3. Daniel Greenfeld pydanny.com / @pydanny http://2scoops.org Danny: 128,546++ Audrey: 121,871++
  • 4. Daniel Greenfeld pydanny.com / @pydanny What I want you to think of me. One Cartwheel of Many Around the World
  • 5. Daniel Greenfeld pydanny.com / @pydanny What I’m really like. Myself at 13 in front of the Apple ][
  • 6. Daniel Greenfeld pydanny.com / @pydanny Overview
  • 7. Daniel Greenfeld pydanny.com / @pydanny Coding into Trouble
  • 8. Daniel Greenfeld pydanny.com / @pydanny Controversy
  • 9. Daniel Greenfeld pydanny.com / @pydanny Exceptions
  • 10. Daniel Greenfeld pydanny.com / @pydanny Avoiding Technical Debt
  • 11. Daniel Greenfeld pydanny.com / @pydanny ...first section...
  • 15. Daniel Greenfeld pydanny.com / @pydanny Circle The super method calls the parent class, which is Circle import math class Circle(object): def __init__(self, radius): self.radius = radius def area(self): return self.radius ** 2 *math.pi def __repr__(self): return '{0} as area {1}'.format( self.__class__.__name__, self.area() ) class Donut(Circle): def __init__(self, outer, inner): super().__init__(outer) self.inner = inner def area(self): outer, inner = self.radius, self.inner return Circle(outer).area() - Circle(inner).area() What if our inheritance isn’t simple? >>> Circle(10) Circle as area 314.159265359 >>> Donut(10, 5) 235.619449019 Superclassing is so easy!
  • 16. Daniel Greenfeld pydanny.com / @pydanny Contention The super() method can create ambiguity.
  • 17. Daniel Greenfeld pydanny.com / @pydanny Example: Django
  • 18. Daniel Greenfeld pydanny.com / @pydanny Class Based Generic Views • Composition • Inheritance • Subclassing • Polymorphism • Lots of other big words used to impress other developers, students, your boss, your doctor, Capoiera mestre, dog, cat, friends, family, and other people who generally don’t care about such things.
  • 19. Daniel Greenfeld pydanny.com / @pydanny However...
  • 20. Daniel Greenfeld pydanny.com / @pydanny Things I don’t know: The ancestor chain for django.views.generic.edit.UpdateView
  • 21. Daniel Greenfeld pydanny.com / @pydanny django.views.generic.edit.UpdateView django.views.generic.detail.SingleObjectTemplateResponseMixin django.views.generic.base.TemplateResponseMixin django.views.generic.edit.BaseUpdateView django.views.generic.edit.ModelFormMixin django.views.generic.edit.FormMixin django.views.generic.detail.SingleObjectMixin django.views.generic.edit.ProcessFormView django.views.generic.base.View The ancestor chain for django.views.generic.edit.UpdateView:
  • 22. Daniel Greenfeld pydanny.com / @pydanny def form_valid(self, form): verb_form = verb_form_base(self.request.POST) if verb_form.is_valid(): form.instance.verb_attributes = verb_form.cleaned_data return super().form_valid(form) A form_valid() implementation OMG Which form_valid() am I calling?
  • 23. Daniel Greenfeld pydanny.com / @pydanny class ActionUpdateView( LoginRequiredMixin, # django-braces ActionBaseView, # inherits from AuthorizedForProtocolMixin AuthorizedforProtocolEditMixin, # Checks rights on edit views VerbBaseView, # Gets one of 200+ verb forms UpdateView): # django.views.generic.BaseView def form_valid(self, form): verb_form = verb_form_base(self.request.POST) if verb_form.is_valid(): form.instance.verb_attributes = verb_form.cleaned_data return super().form_valid(form) A form_valid() implementationOMG! OMG! OMG!
  • 24. Daniel Greenfeld pydanny.com / @pydanny from actions.views import ActionUpdateView for x in ActionUpdateView.mro(): print(x) Ancestor Chain (MRO) of ActionUpdateView MRO = Method Resolution Order Print the MRO
  • 25. Daniel Greenfeld pydanny.com / @pydanny Ancestor Chain (MRO) <class 'actions.views.ActionUpdateView'> <class 'braces.views.LoginRequiredMixin'> <class 'actions.views.ActionBaseView'> <class 'core.views.AuthorizedForProtocolMixin'> <class 'core.views.AuthorizedforProtocolEditMixin'> <class 'verbs.views.VerbBaseView'> <class 'django.views.generic.edit.UpdateView'> <class 'django.views.generic.detail.SingleObjectTemplateResponseMixin'> <class 'django.views.generic.base.TemplateResponseMixin'> <class 'django.views.generic.edit.BaseUpdateView'> <class 'django.views.generic.edit.ModelFormMixin'> <class 'django.views.generic.edit.FormMixin'> <class 'django.views.generic.detail.SingleObjectMixin'> <class 'django.views.generic.edit.ProcessFormView'> <class 'django.views.generic.base.View'> <type 'object'>
  • 26. Daniel Greenfeld pydanny.com / @pydanny from actions.views import ActionUpdateView for x in [x for x in ActionUpdateView.mro() if hasattr(x, "form_valid")]: print(x) Ancestor Chain (MRO) of ActionUpdateView Filter the MRO list to only include classes with a form_valid() nethod
  • 27. Daniel Greenfeld pydanny.com / @pydanny Ancestor Chain (MRO) of <class 'actions.views.ActionUpdateView'> <class 'django.views.generic.edit.UpdateView'> <class 'django.views.generic.edit.BaseUpdateView'> <class 'django.views.generic.edit.ModelFormMixin'> <class 'django.views.generic.edit.FormMixin'> super’s chosen form_valid() ancestor Current class
  • 30. Daniel Greenfeld pydanny.com / @pydanny If you’re not careful, super can cause subtle inheritance/MRO problems.
  • 31. Daniel Greenfeld pydanny.com / @pydanny • Hope that anyone else maintaining this project isn’t going to kill me. • Convert to a functional view. • Explore better patterns. Possible mitigations for this view. • return UpdateView.form_valid(self, form)
  • 32. Daniel Greenfeld pydanny.com / @pydanny Write a easy-to-use MRO inspector thingee that identifies the parent attributes/methods specified by the coder. TODO
  • 34. Daniel Greenfeld pydanny.com / @pydanny Special cases aren’t special enough to break the rules. Although practicality beats purity.* * Zen of Python, lines 8 and 9
  • 35. Daniel Greenfeld pydanny.com / @pydanny Zen of Python $ python -c “import this” The Zen of Python, by Tim Peters 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. 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 first 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! PEP-0020
  • 36. Daniel Greenfeld pydanny.com / @pydanny Special cases aren’t special enough to break the rules. Although practicality beats purity.* * Zen of Python, lines 8 and 9
  • 37. Daniel Greenfeld pydanny.com / @pydanny Web2py Often honors Implicit over Explicit Follows its own namespace pattern
  • 38. Daniel Greenfeld pydanny.com / @pydanny # encoding: utf-8 # https://github.com/mdipierro/evote/blob/master/models/menu.py # this file is released under public domain and # you can use without limitations response.title = 'Voting Service' response.subtitle = None ## read more at http://dev.w3.org/html5/markup/meta.name.html response.meta.author = 'Your Name <you@example.com>' response.meta.description = 'a cool new app' response.meta.keywords = 'web2py, python, framework' response.meta.generator = 'Web2py Web Framework' # snip more content that I cut in the name of brevity Web2py code sample
  • 39. Daniel Greenfeld pydanny.com / @pydanny # encoding: utf-8 # https://github.com/mdipierro/evote/blob/master/models/menu.py # this file is released under public domain and # you can use without limitations response.title = 'Voting Service' response.subtitle = None ## read more at http://dev.w3.org/html5/markup/meta.name.html response.meta.author = 'Your Name <you@example.com>' response.meta.description = 'a cool new app' response.meta.keywords = 'web2py, python, framework' response.meta.generator = 'Web2py Web Framework' # snip more content that I cut in the name of brevity Web2py code sample I GET IT NOW Europe taught me why unicode is important.
  • 40. Daniel Greenfeld pydanny.com / @pydanny # encoding: utf-8 # https://github.com/mdipierro/evote/blob/master/models/menu.py # this file is released under public domain and # you can use without limitations response.title = 'Voting Service' response.subtitle = None ## read more at http://dev.w3.org/html5/markup/meta.name.html response.meta.author = 'Your Name <you@example.com>' response.meta.description = 'a cool new app' response.meta.keywords = 'web2py, python, framework' response.meta.generator = 'Web2py Web Framework' # snip more content that I cut in the name of brevity Web2py code sample OK, Back to the talk...
  • 41. Daniel Greenfeld pydanny.com / @pydanny Web2py code sample # encoding: utf-8 # https://github.com/mdipierro/evote/blob/master/models/menu.py # this file is released under public domain and # you can use without limitations response.title = 'Voting Service' response.subtitle = None ## read more at http://dev.w3.org/html5/markup/meta.name.html response.meta.author = 'Your Name <you@example.com>' response.meta.description = 'a cool new app' response.meta.keywords = 'web2py, python, framework' response.meta.generator = 'Web2py Web Framework' # snip more content that I cut in the name of brevity Response object magically exists. No import necessary What can I expect in any location?What about namespace pollution? Written by Massimo himself
  • 42. Daniel Greenfeld pydanny.com / @pydanny Contention • Explicit is better than implicit • In the name of ambiguity, refuse the temptation to guess • Namespaces are one honking great idea -- let's do more of those! Web2py violates these 3 koans: * Zen of Python, lines 2, 12, 19
  • 43. Daniel Greenfeld pydanny.com / @pydanny Controversy Special cases aren’t special enough to break the rules. Although practicality beats purity.* * Zen of Python, lines 8, 9
  • 44. Daniel Greenfeld pydanny.com / @pydanny Special cases aren’t special enough to break the rules. Although practicality beats purity.* Web2py contends: * Zen of Python, lines 8, 9
  • 45. Daniel Greenfeld pydanny.com / @pydanny Web2py contends: • Implicit behaviors means Web2py is easier for beginners to learn. • The Web2py namespace pattern is easy to learn. • For experienced developers, commonly repeated imports are boilerplate. Note:This is my interpretation of Web2py design considerations. Personal side note:Web2py is very easy to install.
  • 46. Daniel Greenfeld pydanny.com / @pydanny And that’s okay Web2py will always be contentious Web2py argues practicality in some very specific places. Controversy Special cases aren’t special enough to break the rules. Although practicality beats purity.
  • 47. Daniel Greenfeld pydanny.com / @pydanny Flask and its global Request object http://bit.ly/flask-requests A Little Magic Goes a Long Way
  • 48. Daniel Greenfeld pydanny.com / @pydanny Flask and its global Request object http://bit.ly/flask-requests A Little Magic Goes a Long Way
  • 51. Daniel Greenfeld pydanny.com / @pydanny Exceptions Errors should never pass silently. Unless explicitly silenced.* * Zen of Python, lines 10 and 11
  • 52. Daniel Greenfeld pydanny.com / @pydanny djangopackages.com • Once a day iterates across all packages. • Updates the metadata from: • Github: • Bitbucket • PyPI
  • 53. Daniel Greenfeld pydanny.com / @pydanny Django Packages • Sometimes the APIs go down. • Sometimes the APIs change. • Sometimes projects get deleted. • Sometimes the Internets fail Problems Catch and report exceptions!
  • 54. Daniel Greenfeld pydanny.com / @pydanny Old package_updater.py ... for package in Package.objects.all(): try: package.fetch_metadata() package.fetch_commits() except socket_error, e: text += "nFor '%s', threw a socket_error: %s" % (package.title, e) continue # snip lots of other exceptions except Exception as e: text += "nFor '%s', General Exception: %s" % (package.title, e) continue # email later https://github.com/opencomparison/opencomparison/blob/master/package/management/commands/package_updater.py http://bit.ly/Q8v9xk Um...
  • 55. Daniel Greenfeld pydanny.com / @pydanny What I was doing >>> try: ... a = b ... except Exception as e: ... print(e) ... name 'b' is not defined What’s the error type?!? Where is my stack trace?!? (and it’s wrong)
  • 56. Daniel Greenfeld pydanny.com / @pydanny What I wanted >>> a = b Traceback (most recent call last): File "<stdin>", line 1, in <module> NameError: name 'b' is not defined Traceback Error type Error message
  • 57. Daniel Greenfeld pydanny.com / @pydanny Exceptions Errors should never pass silently. Unless explicitly silenced.* My code is nearly silent I’ve silenced things for no good reason * Zen of Python, lines 10 and 11
  • 58. Daniel Greenfeld pydanny.com / @pydanny Getting what I want >>> class CustomErrorHandler(Exception): ... def __init__(self, error): ... print(error) ... print(type(error)) ... >>> try: ... a=b ... except Exception as e: ... raise CustomErrorHandler(e) ... name 'b' is not defined Traceback (most recent call last): File "<stdin>", line 4, in <module> __main__.CustomErrorHandler NameError Traceback Error message For this example print == log No color because it’s a print statement Error Type
  • 59. Daniel Greenfeld pydanny.com / @pydanny PackageUpdaterException Nice message Full traceback All errors caught class PackageUpdaterException(Exception): def __init__(self, error, title): log_message = "For {title}, {error_type}: {error}".format( title=title, error_type=type(error), error=error ) logging.error(log_message) logging.exception(error) for package in Package.objects.all(): try: try: package.fetch_metadata() package.fetch_commits() except Exception as e: raise PackageUpdaterException(e, package.title) except PackageUpdaterException: continue Loop forward
  • 60. Daniel Greenfeld pydanny.com / @pydanny Exceptions Errors should never pass silently. Unless explicitly silenced. My code is nearly silent I’ve silenced things for no good reason
  • 61. Daniel Greenfeld pydanny.com / @pydanny Exceptions Errors should never pass silently. Unless explicitly silenced.
  • 62. Daniel Greenfeld pydanny.com / @pydanny Next up...
  • 64. Daniel Greenfeld pydanny.com / @pydanny Decorators @memoize def allcaps(string): return string.upper() def allcaps(string): return string.upper() allcaps = memoize(allcaps) > Decorators are easy to explain! “A decorator is a function that returns a function.”
  • 65. Daniel Greenfeld pydanny.com / @pydanny I am Zen Decorators == Zen of Python
  • 66. Daniel Greenfeld pydanny.com / @pydanny Until...
  • 67. Daniel Greenfeld pydanny.com / @pydanny I am not Zen I need to write a decorator.
  • 68. Daniel Greenfeld pydanny.com / @pydanny You try to shoot yourself in the foot, only to realize there’s no need, since Guido thoughtfully shot you in the foot years ago. -- Nick Mathewson, comp.lang.python http://starship.python.net/~mwh/quotes.html Ouch
  • 69. Daniel Greenfeld pydanny.com / @pydanny Decorators @memoize def allcaps(string): return string.upper() def allcaps(string): return string.upper() allcaps = memoize(allcaps) > Decorators are easy to explain! “A decorator is a function that returns a function.”
  • 70. Daniel Greenfeld pydanny.com / @pydanny Decorator Template http://pydanny-event-notes.readthedocs.org/en/latest/SCALE10x/python-decorators.html#decorator-template def decorator(function_to_decorate): def wrapper(*args, **kwargs): # do something before invoation result = func_to_decorate(*args, **kwargs) # do something after return result # update wrapper.__doc__ and .func_name # or functools.wraps return wrapper Result is returned when the wrapper is done When decorated function is called decorator returns wrapper Wrapper function does things before and after the function is called here. Wrapper function does things before and after the function is called here.
  • 71. Daniel Greenfeld pydanny.com / @pydanny The Dutch Way 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.* * Zen of Python, lines 13 and 14
  • 72. Daniel Greenfeld pydanny.com / @pydanny Decorator implementation def memoize(func): cache = {} def memoized(*args): if args in cache: return cache[args] result = cache[args] = func(*args) return result return memoized @memoize def allcaps(string): return string.upper() Return function Return value set cache Return value if args in cache Datastore
  • 74. Daniel Greenfeld pydanny.com / @pydanny What about decorators that accept arguments?
  • 76. Daniel Greenfeld pydanny.com / @pydanny Explaining this is Hard. That’s because we create a decorator that creates a parameterized function to wrap the function.
  • 77. Daniel Greenfeld pydanny.com / @pydanny multiplier decorator def multiplier(multiple): def decorator(function): def wrapper(*args, **kwargs): return function(*args, **kwargs) * multiple return wrapper return decorator @multiplier(5) def allcaps(string): return string.upper() Multiplier function sets the state for the multiple argument When decorated function is called the decorator function returns the wrapper function Result is returned when the wrapper is done. Wrapper function does: What am I supposed to highlight?
  • 80. Daniel Greenfeld pydanny.com / @pydanny Not Done Yet!
  • 81. Daniel Greenfeld pydanny.com / @pydanny authentication decorator @authorization('admin') def do_admin_thing(user): # do something administrative return user import functools def authorization(roles): def decorator(function): @functools.wraps(function) def wrapper(*args, **kwargs): check_roles(user, roles) return function(*args, **kwargs) return wrapper return decorator Don’t forget functools!
  • 83. Daniel Greenfeld pydanny.com / @pydanny Really.
  • 84. Daniel Greenfeld pydanny.com / @pydanny I’m not doing class decorators.
  • 85. Daniel Greenfeld pydanny.com / @pydanny It is not easy to explain how to write decorators.
  • 86. Daniel Greenfeld pydanny.com / @pydanny Contention While Using decorators is Zen...
  • 87. Daniel Greenfeld pydanny.com / @pydanny Contention Writing Decorators is Not.
  • 88. Daniel Greenfeld pydanny.com / @pydanny Deep Thought 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. 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. Although practicality beats purity. Decorators are easy to explain! Decorators are hard to explain!
  • 89. Daniel Greenfeld pydanny.com / @pydanny Use the decorator library https://pypi.python.org/pypi/decorator
  • 91. Daniel Greenfeld pydanny.com / @pydanny Getting it done vs. Technical debt Now is better than never. Although never is often better than *right* now. * Zen of Python, lines 15 and 16
  • 92. Daniel Greenfeld pydanny.com / @pydanny • Tests • Documentation Some things take time Risk: Deploying broken code Risk: problems upgrading dependencies Risk: Forgetting install/deploy Risk: Multiple coding standards (Risks of skipping them)
  • 93. Daniel Greenfeld pydanny.com / @pydanny Easy Test Patterns • Always make sure your test harness can run • Try using tests instead of the shell/repl. • After the first deadline, reject any incoming code that drops coverage. • Use coverage.py For developers racing to meet deadlines:
  • 94. Daniel Greenfeld pydanny.com / @pydanny Must-have Documentation • Installation/Deployment procedures • Coding standards • How to run tests • Version (including __version__)
  • 95. Daniel Greenfeld pydanny.com / @pydanny Easy Test Patterns • Always make sure your test harness can run • Try using tests instead of the shell/repl. • Reject any incoming code that drops coverage. • Use coverage.py
  • 96. Daniel Greenfeld pydanny.com / @pydanny Getting technical again...
  • 98. Daniel Greenfeld pydanny.com / @pydanny Namespaces • Extremely powerful • Useful • Precise import re import os from twisted.internet import protocol, reactor from django import forms from myproject import utils
  • 99. Daniel Greenfeld pydanny.com / @pydanny import * makes development faster[1] • Extremely powerful • Useful • Imports everything at once! [2] from re import * from os import * from twisted import * from django.forms import * from myproject.utils import * [1]Warning: import * can be dangerous [2]Warning: import * can be dangerous
  • 100. Daniel Greenfeld pydanny.com / @pydanny Comparing two modules def compare(mod1, mod2): title = 'nComparing {0}, {1}:'.format( mod1.__name__, mod2.__name__ ) print(title) for x in dir(mod1): for y in dir(mod2): if x == y and not x.startswith('_'): print("* " + x)
  • 101. Daniel Greenfeld pydanny.com / @pydanny >>> re.sys == os.sys True >>> re.error == os.error False Comparing two modules >>> import re >>> import os >>> compare(os, re) Comparing os, re: * sys * error import * can get you into trouble from re import * from os import *
  • 102. Daniel Greenfeld pydanny.com / @pydanny Breaking built-ins def compare_builtins(mod1): print("nComparing {0} to builtins:".format(mod1.__name__)) for x in dir(mod1): for y in dir(globals()['__builtins__']): if x == y and not x.startswith('_'): print("* GLOBAL: {0}".format(x)) Checks to see if a module has items that match any Python built-in.
  • 103. Daniel Greenfeld pydanny.com / @pydanny Breaking built-ins >>> compare_builtins(re) Comparing re to builtins: * GLOBAL: compile >>> compare_builtins(os) Comparing os to builtins: * GLOBAL: open from re import * from os import * Breaks compile() built-in. Annoying but infrequent problem. Breaks open() built-in. This can drive you crazy. Compare ‘re’ Compare ‘os’
  • 104. Daniel Greenfeld pydanny.com / @pydanny The open() story from os import *after before Breaks all the things! Help on built-in function open in module __builtin__: open(...) open(name[, mode[, buffering]]) -> file object Open a file using the file() type, returns a file object. This is the preferred way to open a file. See file.__doc__ for further information. Help on built-in function open in module posix: open(...) open(filename, flag [, mode=0777]) -> fd Open a file (for low level IO).
  • 105. Daniel Greenfeld pydanny.com / @pydanny Beginner pro-tip Be careful of tutorials that use import *.
  • 106. Daniel Greenfeld pydanny.com / @pydanny Contention import * is not for beginners. import * is people who really know Python. __all__ = ["echo", "surround", "reverse"]
  • 108. Daniel Greenfeld pydanny.com / @pydanny Stay this person Myself at 13 in front of the Apple ][
  • 109. Daniel Greenfeld pydanny.com / @pydanny Admit What You Don't Know
  • 110. Daniel Greenfeld pydanny.com / @pydanny Stay out of your comfort Zone
  • 112. Daniel Greenfeld pydanny.com / @pydanny What I Want To Know • Twisted • Numpy • SciPy • Tulip • C • Etc.
  • 113. Daniel Greenfeld pydanny.com / @pydanny If I continue to Learn
  • 114. Daniel Greenfeld pydanny.com / @pydanny I Get To Be This Person
  • 115. Daniel Greenfeld pydanny.com / @pydanny Think Hard
  • 116. Daniel Greenfeld pydanny.com / @pydanny Thank you • Armin Ronacher • nephila.it • Richard Jones • Raymond Hettiger • EuroPython • PyKonik • Łukasz Langa • Tomasz Paczkowski
  • 117. Daniel Greenfeld pydanny.com / @pydanny Thank you • Matt Harrison • Ola Sendecka • Kenneth Love • Lennart Regebro • Paul Hildebrandt • Audrey Roy
  • 118. Daniel Greenfeld pydanny.com / @pydanny One More Thing...