PYTHON: From programmer to tamer
Alessandro Pisa - 2013/07/03 - EuroPython 2013
Software Integrator
alessandro.pisa@redturtle.it
http://blog.redturtle.it
@ale_pisa
Alessandro Pisa
HOW I MET PYTHON
It was nice to play football
But rain happens!
Gimme more football!
c64
Something went wrong with Santa...
MSX2
Let the children play
(otherwise bad things happen!)
Blue screen of Death...
...all the time!
Ready to become a Nerd
HARDWARE FAILURES
Let's GIVE Software another chance
True story :(
A lucky afternoon!
Ready to gooooo!
OR NOT?
Question time
It's A HARD LIFE
Only the strongest will survive
RTFM!But...
Documentation is searchable and browsable
http://www.python.org/doc/
Kaizen
Daily homework
http://planet.python.org/
http://twitter.com
http://plus.google.com
...
Don't be afraid of asking help
Any pythonista around
Mailing list
IRC
http://stackoverflow.com
http://www.python.org/community
You are here, and this is
nice!
YOur friend PDB
Get in touch with your gears
Debugging
A nice writeup to start playing with PDB:
http://pymotw.com/2/pdb/
Search for PDB in PyPI: https://pypi.python.org/pypi?%
3Aaction=search&term=pdb+debugger&submit=search
Search debugging tools for your app on PyPI!
No more print
Logging
Logging is an important part
of your code!
Exceptions
EXCEPTIONS ARE an important part of your code!
How good is your code?
https://pypi.python.org/pypi/pep8
https://pypi.python.org/pypi/pyflakes
https://pypi.python.org/pypi/PyChecker
https://pypi.python.org/pypi/pylint
Use PYPI - The Cheeseshop
https://pypi.python.org/pypi
https://testpypi.python.org/pypi
Virtualenv
https://pypi.python.org/pypi/virtualenv
http://docs.python-guide.org/en/latest/dev/virtualenvs.html
http://www.buildout.org/
Forget backup copies
● bazaar (bzr)
● git (git)
● mercurial (hg)
● subversion (svn)
You can choose your place
No warranty about qualitY of life...
● - http://bitbucket.org (git, hg)
● - http://code.google.com (git, hg, svn)
● - http://github.org (git, svn)
● - http://launchpad.net (bzr)
Tickets!
A quite comprehensive list
http://en.wikipedia.org/wiki/Comparison_of_issue-tracking_systems
A ticket aggregator
https://pypi.python.org/pypi/bugwarrior
Tests
Be agile!
Measure twice, cut once!
SCALABILITY
Will your application handle...
... more data?
... more users?
... more REQUEST?
Fail fast!
The times I was bitten by Python!
alessandro.pisa@redturtle.it
http://blog.redturtle.it
@ale_pisa
Nerd wars
● Use the Source, Luke
● The Source will be with you, always
● The Source is strong with this one
● May the Source be with you
https://pypi.python.org/pypi/jedi
Some random tips
Use builtins!
all, any, filter, map, sum, zip, ...
http://docs.python.org/3/library/functions.html
Code like a Pythonista!
http://python.net/~goodger/projects/pycon/2007/idiomatic/handout.html
Context managers!
http://www.python.org/dev/peps/pep-0343/
Use comprehensions
[ale@padme presentations]$python3
>>> [x for x in range(10)]
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
>>> (x for x in range(10))
<generator object <genexpr> at 0xb7187234>
>>> {x for x in range(10)}
{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}
>>> {x:x for x in range(10)}
{0: 0, 1: 1, 2: 2, 3: 3, 4: 4, ..., 9: 9}
Logging
from logging import getLogger
logger = getLogger('Test logger')
def abs_ratio(x, y):
try:
return abs(x / y)
except:
logger.exception('Error abs_ratio: %r, %r' % (x, y))
return -1
abs_ratio(1, None)
abs_ratio(1, 0)
Logging
Error abs_ratio: 1, None
Traceback (most recent call last):
File "logexample.py", line 6, in abs_ratio
return abs(x / y)
TypeError: unsupported operand type(s) for /: 'int'
and 'NoneType'
Error abs_ratio: 1, 0
Traceback (most recent call last):
File "logexample.py", line 6, in abs_ratio
return abs(x / y)
ZeroDivisionError: division by zero
http://pymotw.com/2/logging/
http://pymotw.com/2/exceptions/

More Related Content

PDF
ABYSS OF BADUSB
PDF
Kars Alfrink - Moving Stories
KEY
Python environments
PDF
Coscup2010 opening 0815
PDF
161110
PDF
From Stairway to Heaven onto the Highway to Hell with Xtext
PPTX
How to-train-your-drone v.01
PPT
Python @ PiTech - March 2009
ABYSS OF BADUSB
Kars Alfrink - Moving Stories
Python environments
Coscup2010 opening 0815
161110
From Stairway to Heaven onto the Highway to Hell with Xtext
How to-train-your-drone v.01
Python @ PiTech - March 2009

Similar to PYTHON: From programmer to tamer (20)

PDF
Codebits Handivi
PDF
Caring for file formats
ODP
Learn python
PPTX
Pythonlearn for beginners: An introduction
PPTX
Python learning for everyone-01-Intro.pptx
 
PPTX
Pythonlearn-01-Intro.pptx
PDF
Welcome to Python
PDF
Python introduction
PDF
Infrastructure as code might be literally impossible part 2
 
PDF
What is Python? (Silicon Valley CodeCamp 2014)
PDF
PDF: myths vs facts
PDF
A Whirlwind Tour Of Python
PDF
Introduction to python
PDF
What is Python? (Silicon Valley CodeCamp 2015)
PDF
What is Python?
PPTX
Mastering python lesson1
PDF
Real Python 🐍👨_💻-1.pdf
PDF
The challenges of file formats
PDF
Kafka Summit SF 2017 - Streaming Processing in Python – 10 ways to avoid summ...
PPT
PythonCourse_01_Intro.ppt Python introduction turorial for beginner.
Codebits Handivi
Caring for file formats
Learn python
Pythonlearn for beginners: An introduction
Python learning for everyone-01-Intro.pptx
 
Pythonlearn-01-Intro.pptx
Welcome to Python
Python introduction
Infrastructure as code might be literally impossible part 2
 
What is Python? (Silicon Valley CodeCamp 2014)
PDF: myths vs facts
A Whirlwind Tour Of Python
Introduction to python
What is Python? (Silicon Valley CodeCamp 2015)
What is Python?
Mastering python lesson1
Real Python 🐍👨_💻-1.pdf
The challenges of file formats
Kafka Summit SF 2017 - Streaming Processing in Python – 10 ways to avoid summ...
PythonCourse_01_Intro.ppt Python introduction turorial for beginner.
Ad

Recently uploaded (20)

PPTX
Web Crawler for Trend Tracking Gen Z Insights.pptx
PDF
Hindi spoken digit analysis for native and non-native speakers
PPTX
Benefits of Physical activity for teenagers.pptx
PPTX
Final SEM Unit 1 for mit wpu at pune .pptx
PDF
A review of recent deep learning applications in wood surface defect identifi...
PDF
Zenith AI: Advanced Artificial Intelligence
PDF
Developing a website for English-speaking practice to English as a foreign la...
PDF
Getting Started with Data Integration: FME Form 101
PDF
A Late Bloomer's Guide to GenAI: Ethics, Bias, and Effective Prompting - Boha...
PPT
What is a Computer? Input Devices /output devices
PDF
WOOl fibre morphology and structure.pdf for textiles
PPTX
Chapter 5: Probability Theory and Statistics
PPTX
Modernising the Digital Integration Hub
PDF
CloudStack 4.21: First Look Webinar slides
PDF
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
PDF
Assigned Numbers - 2025 - BluetoothÂŽ Document
PDF
How ambidextrous entrepreneurial leaders react to the artificial intelligence...
PDF
DP Operators-handbook-extract for the Mautical Institute
PDF
1 - Historical Antecedents, Social Consideration.pdf
PDF
Hybrid model detection and classification of lung cancer
Web Crawler for Trend Tracking Gen Z Insights.pptx
Hindi spoken digit analysis for native and non-native speakers
Benefits of Physical activity for teenagers.pptx
Final SEM Unit 1 for mit wpu at pune .pptx
A review of recent deep learning applications in wood surface defect identifi...
Zenith AI: Advanced Artificial Intelligence
Developing a website for English-speaking practice to English as a foreign la...
Getting Started with Data Integration: FME Form 101
A Late Bloomer's Guide to GenAI: Ethics, Bias, and Effective Prompting - Boha...
What is a Computer? Input Devices /output devices
WOOl fibre morphology and structure.pdf for textiles
Chapter 5: Probability Theory and Statistics
Modernising the Digital Integration Hub
CloudStack 4.21: First Look Webinar slides
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
Assigned Numbers - 2025 - BluetoothÂŽ Document
How ambidextrous entrepreneurial leaders react to the artificial intelligence...
DP Operators-handbook-extract for the Mautical Institute
1 - Historical Antecedents, Social Consideration.pdf
Hybrid model detection and classification of lung cancer
Ad

PYTHON: From programmer to tamer