SlideShare a Scribd company logo
How to train your Python! 
be a pythonista! 
Par Jordi Riera 
La marque de commerce Linux® est utilisée conformément à une sous-licence de LMI, licencié exclusif de Linus Torvalds, propriétaire de la marque au niveau mondial .
Jordi Riera - Odoo Technical Consultant & Python Developer 
7 ans d'expérience en pipeline dont : 
- Pipeline développeur à MPC 
- Pipeline TD à Sony Pictures Imageworks
Vous et python?
1. Introduction à ipython 
2. Pimp my code
ipython
ipython : le shell des vrais et durs! 
voir des feignants... 
Savoir-faire Linux | 6
● Powerful interactive shells (terminal and Qt-based). 
● A browser-based notebook with support for code, text, mathematical expressivons, 
inline plots and other rich media. 
● Support for interactive data visualization and use of GUI toolkits. 
● Flexible, embeddable interpreters to load into your own projects. 
● Easy to use, high performance tools for parallel computing. 
ipython.org 
Savoir-faire Linux | 7
En direct de votre Shell : > ipython 
> pip install ipython
ou du browser : > ipython notebook
Pimp my code
Loopers
for est un foreach 
In [1]: speakers = ['Christian', 'Eric', 'Dave', 'Jordi'] 
In [2]: for i in range(len(speakers)): 
...: print speakers[i] 
In [3]: for speaker in speakers: 
...: print speaker
Index dans une boucle for 
In [1]: speakers = ['Christian', 'Eric', 'Dave', 'Jordi'] 
In [2]: for i in range(len(speakers)): 
...: print i, speakers[i]
Index dans une boucle for 
In [1]: speakers = ['Christian', 'Eric', 'Dave', 'Jordi'] 
In [2]: for i in range(len(speakers)): 
...: print i, speakers[i] 
In [3]: for i, speaker in enumerate(speakers): 
...: print i, speaker
range 
In [1]: for i in [0, 1, 2, 3, 4, 5]: 
...: print i 
In [2]: for i in range(6): 
...: print i
range 
In [1]: for i in [0, 1, 2, 3, 4, 5]: 
...: print i 
In [2]: for i in range(6): 
...: print i 
In [3]: for i in xrange(6): 
...: print i
Compréhension à la portée de tous 
In [1]: a = [] 
In [2]: for i in xrange(10): 
...: if not i % 2: 
...: a.append(i) 
In [3]: a 
Out[3]: [0, 2, 4, 6, 8]
Compréhension à la portée de tous 
In [1]: a = [] 
In [2]: for i in xrange(10): 
...: if not i % 2: 
...: a.append(i) 
In [3]: a 
Out[3]: [0, 2, 4, 6, 8] 
In [4]: a = [i for i in xrange(10) if not i % 2] 
In [5]: a 
Out[5]: [0, 2, 4, 6, 8]
Almost all set 
In [1]: a = range(10000) + range(20000) + range(30000) 
In [2]: b = [] 
In [3]: for i in a: 
...: if not i in b: 
...: b.append(i)
Almost all set 
In [1]: a = range(10000) + range(20000) + range(30000) 
In [2]: b = [] 
In [3]: for i in a: 
...: if not i in b: 
...: b.append(i) 
In [1]: a = range(10000) + range(20000) + range(30000) 
In [2]: b = list(set(a))
The Great Dictionnary
Construire un dict à partir de listes 
In [1]: companies = ['sfl', 'nad'] 
In [2]: people = (['John', 'Jonathan', 'Jordi'], ['Christian']) 
In [3]: d = {} 
In [4]: for i, company in enumerate(companies): 
...: d[company] = people[i] 
...:
Construire un dict à partir de listes 
In [1]: companies = ['sfl', 'nad'] 
In [2]: people = (['John', 'Jonathan', 'Jordi'], ['Christian']) 
In [3]: d = {} 
In [4]: for i, company in enumerate(companies): 
...: d[company] = people[i] 
...: 
In [5]: d = dict(izip(companies, people)) 
Out[5]: {'nad': ['Christian'], 'sfl': ['John', 'Jonathan', 'Jordi']}
Boucles dans un dict 
In [1]: details = { 
'sfl': ['John', 'Jonathan', 'Jordi'], 
'nad': ['Christian'] 
} 
In [2]: for key in details.keys(): 
...: print key
Boucles dans un dict 
In [1]: details = { 
'sfl': ['John', 'Jonathan', 'Jordi'], 
'nad': ['Christian'] 
} 
In [2]: for key in details.keys(): 
...: print key 
In [3]: for key in details: 
...: print key
Boucles dans un dict 
In [1]: details = { 
'sfl': ['John', 'Jonathan', 'Jordi'], 
'nad': ['Christian'] 
} 
In [2]: for key in details.keys(): 
...: print key 
In [3]: for key in details: 
...: print key 
In [4]: for key in details.iterkeys(): 
...: print key
Iteration mais pas tout le temps 
In [1]: for k in details.iterkeys(): 
....: if k == 'sfl': 
....: del details[k] 
RuntimeError: dictionary changed size during iteration
Iteration mais pas tout le temps 
In [1]: for k in details.iterkeys(): 
....: if k == 'sfl': 
....: del details[k] 
RuntimeError: dictionary changed size during iteration 
In [2]: for k in details.keys(): 
....: if k == 'sfl': 
....: del details[k]
Boucles dans un dict 
Autres outils d'itérations dans un dictionnaire: 
.keys() <-> .iterkeys() 
.values() <-> .itervalues() 
.items() <-> .iteritems()
Remplir un dictionnaire 
In [1]: people = (['John', 'sfl'], ['Jonathan', 'sfl'], ['Jordi', 'sfl'], 
['Christian', 'nad']) 
In [2]: d = {} 
In [3]: for p, company in peopls.iteritems(): 
...: if company not in d: 
...: d[company] = [] 
...: d[company].append(p)
Remplir un dictionnaire 
In [1]: people = (['John', 'sfl'], ['Jonathan', 'sfl'], ['Jordi', 'sfl'], 
['Christian', 'nad']) 
In [2]: d = {} 
In [3]: for p, company in people.iteritems(): 
...: if company not in d: 
...: d[company] = [] 
...: d[company].append(p) 
In [4]: for p, company in people.iteritems(): 
....: d.setdefault(company, []).append(p)
Remplir un dictionnaire 
In [5]: from collections import defaultdict 
In [6]: d = defaultdict(list) 
In [7]: for p, company in people.iteritems(): 
....: d[company].append(p)
The Bone Collections
In [1]: {'john': 'sfl', 'jonathan': 'sfl', 'jordi':'sfl' , 'christian':'nad'} 
Out[1]: {'christian': 'nad', 'john': 'sfl', 'jonathan': 'sfl', 'jordi': 'sfl'}
OrderedDict 
In [1]: {'john': 'sfl', 'jonathan': 'sfl', 'jordi':'sfl' , 'christian':'nad'} 
Out[1]: {'christian': 'nad', 'john': 'sfl', 'jonathan': 'sfl', 'jordi': 'sfl'} 
In [2]: d = OrderedDict() 
In [3]: d['John'] = 'sfl' 
In [4]: d['Jonathan'] = 'sfl' 
In [5]: d['Jordi'] = 'sfl' 
In [6]: d['Christian'] = 'nad' 
In [7]: d 
Out[7]: OrderedDict([('John', 'sfl'), ('Jonathan', 'sfl'), ('Jordi', 'sfl'), 
('Christian', 'nad')])
namedtuple 
In [1]: get_points() 
Out[1]: [(65, 28, 45, 255, 255, 87), (255, 255, 87, 65, 28, 45)] 
In [2]: get_points() 
Out[2]: [Coord_color(x=65, y=28, z=45, r=255, g=255, b=87), 
Coord_color(x=255, y=255, z=87, r=65, g=28, b=45)]
namedtuple 
In [1]: from collections import namedtuple 
In [2]: Coord_color = namedtuple('Coord_color', ['x', 'y', 'z', 'r', 'g', 'b']) 
In [3]: [Coord_color(65, 28, 45, 255, 255, 87), Coord_color(255, 255, 87, 65, 
28, 45)] 
Out[3]: [Coord_color(x=65, y=28, z=45, r=255, g=255, b=87), 
Coord_color(x=255, y=255, z=87, r=65, g=28, b=45)] 
Namedtuple est une sous classe de tuple, lui donnant les mêmes 
méthodes qu'un tuple.
1-877-735-4689 
contact@savoirfairelinux.com 
http://www.savoirfairelinux.com
Nous recrutons! 
http://carrieres.savoirfairelinux.com/

More Related Content

Viewers also liked

SHOWDOWN: Threat Stack vs. Red Hat AuditD
SHOWDOWN: Threat Stack vs. Red Hat AuditDSHOWDOWN: Threat Stack vs. Red Hat AuditD
SHOWDOWN: Threat Stack vs. Red Hat AuditD
Threat Stack
 
Audit
AuditAudit
Protecting confidential files using SE-Linux
Protecting confidential files using SE-LinuxProtecting confidential files using SE-Linux
Protecting confidential files using SE-Linux
Giuseppe Paterno'
 
Linux audit framework
Linux audit frameworkLinux audit framework
Linux audit framework
Torstein Hansen
 
Open Audit
Open AuditOpen Audit
Open Audit
ncspa
 
Dealing with Linux Malware
Dealing with Linux MalwareDealing with Linux Malware
Dealing with Linux Malware
Michael Boelen
 
Bringing Infosec Into The Devops Tribe: Q&A With Gene Kim and Pete Cheslock
Bringing Infosec Into The Devops Tribe: Q&A With Gene Kim and Pete CheslockBringing Infosec Into The Devops Tribe: Q&A With Gene Kim and Pete Cheslock
Bringing Infosec Into The Devops Tribe: Q&A With Gene Kim and Pete Cheslock
Threat Stack
 
Everyone Matters In Infosec 2014
Everyone Matters In Infosec 2014Everyone Matters In Infosec 2014
Everyone Matters In Infosec 2014
Micah Hoffman
 
Whitepaper: User Audit Options for Linux and Solaris
Whitepaper: User Audit Options for Linux and SolarisWhitepaper: User Audit Options for Linux and Solaris
Whitepaper: User Audit Options for Linux and Solaris
ObserveIT
 
Python build your security tools.pdf
Python build your security tools.pdfPython build your security tools.pdf
Python build your security tools.pdf
TECHNOLOGY CONTROL CO.
 
MySQL Day Paris 2016 - MySQL Enterprise Edition
MySQL Day Paris 2016 - MySQL Enterprise EditionMySQL Day Paris 2016 - MySQL Enterprise Edition
MySQL Day Paris 2016 - MySQL Enterprise Edition
Olivier DASINI
 
2009-08-11 IBM Teach the Teachers (IBM T3), Linux Security Overview
2009-08-11 IBM Teach the Teachers (IBM T3), Linux Security Overview2009-08-11 IBM Teach the Teachers (IBM T3), Linux Security Overview
2009-08-11 IBM Teach the Teachers (IBM T3), Linux Security Overview
Shawn Wells
 
Network Security and Analysis with Python
Network Security and Analysis with PythonNetwork Security and Analysis with Python
Network Security and Analysis with Python
pycontw
 
Linux Security Scanning with Lynis
Linux Security Scanning with LynisLinux Security Scanning with Lynis
Linux Security Scanning with Lynis
Michael Boelen
 
Handling of compromised Linux systems
Handling of compromised Linux systemsHandling of compromised Linux systems
Handling of compromised Linux systems
Michael Boelen
 
Linux Hardening
Linux HardeningLinux Hardening
Linux Hardening
Michael Boelen
 
PowerShell for Penetration Testers
PowerShell for Penetration TestersPowerShell for Penetration Testers
PowerShell for Penetration Testers
Nikhil Mittal
 
Linux Security for Developers
Linux Security for DevelopersLinux Security for Developers
Linux Security for Developers
Michael Boelen
 
AMSI: How Windows 10 Plans to Stop Script-Based Attacks and How Well It Does It
AMSI: How Windows 10 Plans to Stop Script-Based Attacks and How Well It Does ItAMSI: How Windows 10 Plans to Stop Script-Based Attacks and How Well It Does It
AMSI: How Windows 10 Plans to Stop Script-Based Attacks and How Well It Does It
Nikhil Mittal
 
PowerUp - Automating Windows Privilege Escalation
PowerUp - Automating Windows Privilege EscalationPowerUp - Automating Windows Privilege Escalation
PowerUp - Automating Windows Privilege Escalation
Will Schroeder
 

Viewers also liked (20)

SHOWDOWN: Threat Stack vs. Red Hat AuditD
SHOWDOWN: Threat Stack vs. Red Hat AuditDSHOWDOWN: Threat Stack vs. Red Hat AuditD
SHOWDOWN: Threat Stack vs. Red Hat AuditD
 
Audit
AuditAudit
Audit
 
Protecting confidential files using SE-Linux
Protecting confidential files using SE-LinuxProtecting confidential files using SE-Linux
Protecting confidential files using SE-Linux
 
Linux audit framework
Linux audit frameworkLinux audit framework
Linux audit framework
 
Open Audit
Open AuditOpen Audit
Open Audit
 
Dealing with Linux Malware
Dealing with Linux MalwareDealing with Linux Malware
Dealing with Linux Malware
 
Bringing Infosec Into The Devops Tribe: Q&A With Gene Kim and Pete Cheslock
Bringing Infosec Into The Devops Tribe: Q&A With Gene Kim and Pete CheslockBringing Infosec Into The Devops Tribe: Q&A With Gene Kim and Pete Cheslock
Bringing Infosec Into The Devops Tribe: Q&A With Gene Kim and Pete Cheslock
 
Everyone Matters In Infosec 2014
Everyone Matters In Infosec 2014Everyone Matters In Infosec 2014
Everyone Matters In Infosec 2014
 
Whitepaper: User Audit Options for Linux and Solaris
Whitepaper: User Audit Options for Linux and SolarisWhitepaper: User Audit Options for Linux and Solaris
Whitepaper: User Audit Options for Linux and Solaris
 
Python build your security tools.pdf
Python build your security tools.pdfPython build your security tools.pdf
Python build your security tools.pdf
 
MySQL Day Paris 2016 - MySQL Enterprise Edition
MySQL Day Paris 2016 - MySQL Enterprise EditionMySQL Day Paris 2016 - MySQL Enterprise Edition
MySQL Day Paris 2016 - MySQL Enterprise Edition
 
2009-08-11 IBM Teach the Teachers (IBM T3), Linux Security Overview
2009-08-11 IBM Teach the Teachers (IBM T3), Linux Security Overview2009-08-11 IBM Teach the Teachers (IBM T3), Linux Security Overview
2009-08-11 IBM Teach the Teachers (IBM T3), Linux Security Overview
 
Network Security and Analysis with Python
Network Security and Analysis with PythonNetwork Security and Analysis with Python
Network Security and Analysis with Python
 
Linux Security Scanning with Lynis
Linux Security Scanning with LynisLinux Security Scanning with Lynis
Linux Security Scanning with Lynis
 
Handling of compromised Linux systems
Handling of compromised Linux systemsHandling of compromised Linux systems
Handling of compromised Linux systems
 
Linux Hardening
Linux HardeningLinux Hardening
Linux Hardening
 
PowerShell for Penetration Testers
PowerShell for Penetration TestersPowerShell for Penetration Testers
PowerShell for Penetration Testers
 
Linux Security for Developers
Linux Security for DevelopersLinux Security for Developers
Linux Security for Developers
 
AMSI: How Windows 10 Plans to Stop Script-Based Attacks and How Well It Does It
AMSI: How Windows 10 Plans to Stop Script-Based Attacks and How Well It Does ItAMSI: How Windows 10 Plans to Stop Script-Based Attacks and How Well It Does It
AMSI: How Windows 10 Plans to Stop Script-Based Attacks and How Well It Does It
 
PowerUp - Automating Windows Privilege Escalation
PowerUp - Automating Windows Privilege EscalationPowerUp - Automating Windows Privilege Escalation
PowerUp - Automating Windows Privilege Escalation
 

Similar to How To Train Your Python

ch1_slides.pdf
ch1_slides.pdfch1_slides.pdf
ch1_slides.pdf
YuanlongZhang3
 
Python Puzzlers
Python PuzzlersPython Puzzlers
Python Puzzlers
Tendayi Mawushe
 
Python slide
Python slidePython slide
A Few of My Favorite (Python) Things
A Few of My Favorite (Python) ThingsA Few of My Favorite (Python) Things
A Few of My Favorite (Python) Things
Michael Pirnat
 
Dictionary in python
Dictionary in pythonDictionary in python
Dictionary in python
vikram mahendra
 
intro_to_python_20150825
intro_to_python_20150825intro_to_python_20150825
intro_to_python_20150825
Shung-Hsi Yu
 
Python于Web 2.0网站的应用 - QCon Beijing 2010
Python于Web 2.0网站的应用 - QCon Beijing 2010Python于Web 2.0网站的应用 - QCon Beijing 2010
Python于Web 2.0网站的应用 - QCon Beijing 2010
Qiangning Hong
 
Python 101 1
Python 101   1Python 101   1
Python 101 1
Iccha Sethi
 
2 UNIT CH3 Dictionaries v1.ppt
2 UNIT CH3 Dictionaries v1.ppt2 UNIT CH3 Dictionaries v1.ppt
2 UNIT CH3 Dictionaries v1.ppt
tocidfh
 
Basics of Python programming (part 2)
Basics of Python programming (part 2)Basics of Python programming (part 2)
Basics of Python programming (part 2)
Pedro Rodrigues
 
Python for Dummies
Python for DummiesPython for Dummies
Python for Dummies
Leonardo Jimenez
 
CS 151 dictionary objects
CS 151 dictionary objectsCS 151 dictionary objects
CS 151 dictionary objects
Rudy Martinez
 
Intro to Python
Intro to PythonIntro to Python
Intro to Python
Eugene Petrusha
 
PMED Undergraduate Workshop - R Tutorial for PMED Undegraduate Workshop - Xi...
PMED Undergraduate Workshop - R Tutorial for PMED Undegraduate Workshop  - Xi...PMED Undergraduate Workshop - R Tutorial for PMED Undegraduate Workshop  - Xi...
PMED Undergraduate Workshop - R Tutorial for PMED Undegraduate Workshop - Xi...
The Statistical and Applied Mathematical Sciences Institute
 
Practical File Grade 12.pdf
Practical File Grade 12.pdfPractical File Grade 12.pdf
Practical File Grade 12.pdf
dipanshujoshi8869
 
Becoming a Pythonist
Becoming a PythonistBecoming a Pythonist
Becoming a Pythonist
Raji Engg
 
Python for data science by www.dmdiploma.com
Python for data science by www.dmdiploma.comPython for data science by www.dmdiploma.com
Python for data science by www.dmdiploma.com
ShwetaAggarwal56
 
R for Pythonistas (PyData NYC 2017)
R for Pythonistas (PyData NYC 2017)R for Pythonistas (PyData NYC 2017)
R for Pythonistas (PyData NYC 2017)
Christopher Roach
 
Python dictionaries
Python dictionariesPython dictionaries
Python dictionaries
Krishna Nanda
 
Procesamiento del lenguaje natural con python
Procesamiento del lenguaje natural con pythonProcesamiento del lenguaje natural con python
Procesamiento del lenguaje natural con python
Facultad de Ciencias y Sistemas
 

Similar to How To Train Your Python (20)

ch1_slides.pdf
ch1_slides.pdfch1_slides.pdf
ch1_slides.pdf
 
Python Puzzlers
Python PuzzlersPython Puzzlers
Python Puzzlers
 
Python slide
Python slidePython slide
Python slide
 
A Few of My Favorite (Python) Things
A Few of My Favorite (Python) ThingsA Few of My Favorite (Python) Things
A Few of My Favorite (Python) Things
 
Dictionary in python
Dictionary in pythonDictionary in python
Dictionary in python
 
intro_to_python_20150825
intro_to_python_20150825intro_to_python_20150825
intro_to_python_20150825
 
Python于Web 2.0网站的应用 - QCon Beijing 2010
Python于Web 2.0网站的应用 - QCon Beijing 2010Python于Web 2.0网站的应用 - QCon Beijing 2010
Python于Web 2.0网站的应用 - QCon Beijing 2010
 
Python 101 1
Python 101   1Python 101   1
Python 101 1
 
2 UNIT CH3 Dictionaries v1.ppt
2 UNIT CH3 Dictionaries v1.ppt2 UNIT CH3 Dictionaries v1.ppt
2 UNIT CH3 Dictionaries v1.ppt
 
Basics of Python programming (part 2)
Basics of Python programming (part 2)Basics of Python programming (part 2)
Basics of Python programming (part 2)
 
Python for Dummies
Python for DummiesPython for Dummies
Python for Dummies
 
CS 151 dictionary objects
CS 151 dictionary objectsCS 151 dictionary objects
CS 151 dictionary objects
 
Intro to Python
Intro to PythonIntro to Python
Intro to Python
 
PMED Undergraduate Workshop - R Tutorial for PMED Undegraduate Workshop - Xi...
PMED Undergraduate Workshop - R Tutorial for PMED Undegraduate Workshop  - Xi...PMED Undergraduate Workshop - R Tutorial for PMED Undegraduate Workshop  - Xi...
PMED Undergraduate Workshop - R Tutorial for PMED Undegraduate Workshop - Xi...
 
Practical File Grade 12.pdf
Practical File Grade 12.pdfPractical File Grade 12.pdf
Practical File Grade 12.pdf
 
Becoming a Pythonist
Becoming a PythonistBecoming a Pythonist
Becoming a Pythonist
 
Python for data science by www.dmdiploma.com
Python for data science by www.dmdiploma.comPython for data science by www.dmdiploma.com
Python for data science by www.dmdiploma.com
 
R for Pythonistas (PyData NYC 2017)
R for Pythonistas (PyData NYC 2017)R for Pythonistas (PyData NYC 2017)
R for Pythonistas (PyData NYC 2017)
 
Python dictionaries
Python dictionariesPython dictionaries
Python dictionaries
 
Procesamiento del lenguaje natural con python
Procesamiento del lenguaje natural con pythonProcesamiento del lenguaje natural con python
Procesamiento del lenguaje natural con python
 

Recently uploaded

SQL Accounting Software Brochure Malaysia
SQL Accounting Software Brochure MalaysiaSQL Accounting Software Brochure Malaysia
SQL Accounting Software Brochure Malaysia
GohKiangHock
 
UI5con 2024 - Bring Your Own Design System
UI5con 2024 - Bring Your Own Design SystemUI5con 2024 - Bring Your Own Design System
UI5con 2024 - Bring Your Own Design System
Peter Muessig
 
Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Łukasz Chruściel
 
How Can Hiring A Mobile App Development Company Help Your Business Grow?
How Can Hiring A Mobile App Development Company Help Your Business Grow?How Can Hiring A Mobile App Development Company Help Your Business Grow?
How Can Hiring A Mobile App Development Company Help Your Business Grow?
ToXSL Technologies
 
SMS API Integration in Saudi Arabia| Best SMS API Service
SMS API Integration in Saudi Arabia| Best SMS API ServiceSMS API Integration in Saudi Arabia| Best SMS API Service
SMS API Integration in Saudi Arabia| Best SMS API Service
Yara Milbes
 
E-commerce Development Services- Hornet Dynamics
E-commerce Development Services- Hornet DynamicsE-commerce Development Services- Hornet Dynamics
E-commerce Development Services- Hornet Dynamics
Hornet Dynamics
 
Odoo ERP Vs. Traditional ERP Systems – A Comparative Analysis
Odoo ERP Vs. Traditional ERP Systems – A Comparative AnalysisOdoo ERP Vs. Traditional ERP Systems – A Comparative Analysis
Odoo ERP Vs. Traditional ERP Systems – A Comparative Analysis
Envertis Software Solutions
 
Top 9 Trends in Cybersecurity for 2024.pptx
Top 9 Trends in Cybersecurity for 2024.pptxTop 9 Trends in Cybersecurity for 2024.pptx
Top 9 Trends in Cybersecurity for 2024.pptx
devvsandy
 
Unveiling the Advantages of Agile Software Development.pdf
Unveiling the Advantages of Agile Software Development.pdfUnveiling the Advantages of Agile Software Development.pdf
Unveiling the Advantages of Agile Software Development.pdf
brainerhub1
 
8 Best Automated Android App Testing Tool and Framework in 2024.pdf
8 Best Automated Android App Testing Tool and Framework in 2024.pdf8 Best Automated Android App Testing Tool and Framework in 2024.pdf
8 Best Automated Android App Testing Tool and Framework in 2024.pdf
kalichargn70th171
 
Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...
Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...
Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...
XfilesPro
 
Requirement Traceability in Xen Functional Safety
Requirement Traceability in Xen Functional SafetyRequirement Traceability in Xen Functional Safety
Requirement Traceability in Xen Functional Safety
Ayan Halder
 
Microservice Teams - How the cloud changes the way we work
Microservice Teams - How the cloud changes the way we workMicroservice Teams - How the cloud changes the way we work
Microservice Teams - How the cloud changes the way we work
Sven Peters
 
Malibou Pitch Deck For Its €3M Seed Round
Malibou Pitch Deck For Its €3M Seed RoundMalibou Pitch Deck For Its €3M Seed Round
Malibou Pitch Deck For Its €3M Seed Round
sjcobrien
 
Using Query Store in Azure PostgreSQL to Understand Query Performance
Using Query Store in Azure PostgreSQL to Understand Query PerformanceUsing Query Store in Azure PostgreSQL to Understand Query Performance
Using Query Store in Azure PostgreSQL to Understand Query Performance
Grant Fritchey
 
Energy consumption of Database Management - Florina Jonuzi
Energy consumption of Database Management - Florina JonuziEnergy consumption of Database Management - Florina Jonuzi
Energy consumption of Database Management - Florina Jonuzi
Green Software Development
 
Enums On Steroids - let's look at sealed classes !
Enums On Steroids - let's look at sealed classes !Enums On Steroids - let's look at sealed classes !
Enums On Steroids - let's look at sealed classes !
Marcin Chrost
 
socradar-q1-2024-aviation-industry-report.pdf
socradar-q1-2024-aviation-industry-report.pdfsocradar-q1-2024-aviation-industry-report.pdf
socradar-q1-2024-aviation-industry-report.pdf
SOCRadar
 
Mobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona InfotechMobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona Infotech
Drona Infotech
 
How to write a program in any programming language
How to write a program in any programming languageHow to write a program in any programming language
How to write a program in any programming language
Rakesh Kumar R
 

Recently uploaded (20)

SQL Accounting Software Brochure Malaysia
SQL Accounting Software Brochure MalaysiaSQL Accounting Software Brochure Malaysia
SQL Accounting Software Brochure Malaysia
 
UI5con 2024 - Bring Your Own Design System
UI5con 2024 - Bring Your Own Design SystemUI5con 2024 - Bring Your Own Design System
UI5con 2024 - Bring Your Own Design System
 
Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️
 
How Can Hiring A Mobile App Development Company Help Your Business Grow?
How Can Hiring A Mobile App Development Company Help Your Business Grow?How Can Hiring A Mobile App Development Company Help Your Business Grow?
How Can Hiring A Mobile App Development Company Help Your Business Grow?
 
SMS API Integration in Saudi Arabia| Best SMS API Service
SMS API Integration in Saudi Arabia| Best SMS API ServiceSMS API Integration in Saudi Arabia| Best SMS API Service
SMS API Integration in Saudi Arabia| Best SMS API Service
 
E-commerce Development Services- Hornet Dynamics
E-commerce Development Services- Hornet DynamicsE-commerce Development Services- Hornet Dynamics
E-commerce Development Services- Hornet Dynamics
 
Odoo ERP Vs. Traditional ERP Systems – A Comparative Analysis
Odoo ERP Vs. Traditional ERP Systems – A Comparative AnalysisOdoo ERP Vs. Traditional ERP Systems – A Comparative Analysis
Odoo ERP Vs. Traditional ERP Systems – A Comparative Analysis
 
Top 9 Trends in Cybersecurity for 2024.pptx
Top 9 Trends in Cybersecurity for 2024.pptxTop 9 Trends in Cybersecurity for 2024.pptx
Top 9 Trends in Cybersecurity for 2024.pptx
 
Unveiling the Advantages of Agile Software Development.pdf
Unveiling the Advantages of Agile Software Development.pdfUnveiling the Advantages of Agile Software Development.pdf
Unveiling the Advantages of Agile Software Development.pdf
 
8 Best Automated Android App Testing Tool and Framework in 2024.pdf
8 Best Automated Android App Testing Tool and Framework in 2024.pdf8 Best Automated Android App Testing Tool and Framework in 2024.pdf
8 Best Automated Android App Testing Tool and Framework in 2024.pdf
 
Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...
Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...
Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...
 
Requirement Traceability in Xen Functional Safety
Requirement Traceability in Xen Functional SafetyRequirement Traceability in Xen Functional Safety
Requirement Traceability in Xen Functional Safety
 
Microservice Teams - How the cloud changes the way we work
Microservice Teams - How the cloud changes the way we workMicroservice Teams - How the cloud changes the way we work
Microservice Teams - How the cloud changes the way we work
 
Malibou Pitch Deck For Its €3M Seed Round
Malibou Pitch Deck For Its €3M Seed RoundMalibou Pitch Deck For Its €3M Seed Round
Malibou Pitch Deck For Its €3M Seed Round
 
Using Query Store in Azure PostgreSQL to Understand Query Performance
Using Query Store in Azure PostgreSQL to Understand Query PerformanceUsing Query Store in Azure PostgreSQL to Understand Query Performance
Using Query Store in Azure PostgreSQL to Understand Query Performance
 
Energy consumption of Database Management - Florina Jonuzi
Energy consumption of Database Management - Florina JonuziEnergy consumption of Database Management - Florina Jonuzi
Energy consumption of Database Management - Florina Jonuzi
 
Enums On Steroids - let's look at sealed classes !
Enums On Steroids - let's look at sealed classes !Enums On Steroids - let's look at sealed classes !
Enums On Steroids - let's look at sealed classes !
 
socradar-q1-2024-aviation-industry-report.pdf
socradar-q1-2024-aviation-industry-report.pdfsocradar-q1-2024-aviation-industry-report.pdf
socradar-q1-2024-aviation-industry-report.pdf
 
Mobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona InfotechMobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona Infotech
 
How to write a program in any programming language
How to write a program in any programming languageHow to write a program in any programming language
How to write a program in any programming language
 

How To Train Your Python

  • 1. How to train your Python! be a pythonista! Par Jordi Riera La marque de commerce Linux® est utilisée conformément à une sous-licence de LMI, licencié exclusif de Linus Torvalds, propriétaire de la marque au niveau mondial .
  • 2. Jordi Riera - Odoo Technical Consultant & Python Developer 7 ans d'expérience en pipeline dont : - Pipeline développeur à MPC - Pipeline TD à Sony Pictures Imageworks
  • 4. 1. Introduction à ipython 2. Pimp my code
  • 6. ipython : le shell des vrais et durs! voir des feignants... Savoir-faire Linux | 6
  • 7. ● Powerful interactive shells (terminal and Qt-based). ● A browser-based notebook with support for code, text, mathematical expressivons, inline plots and other rich media. ● Support for interactive data visualization and use of GUI toolkits. ● Flexible, embeddable interpreters to load into your own projects. ● Easy to use, high performance tools for parallel computing. ipython.org Savoir-faire Linux | 7
  • 8. En direct de votre Shell : > ipython > pip install ipython
  • 9. ou du browser : > ipython notebook
  • 12. for est un foreach In [1]: speakers = ['Christian', 'Eric', 'Dave', 'Jordi'] In [2]: for i in range(len(speakers)): ...: print speakers[i] In [3]: for speaker in speakers: ...: print speaker
  • 13. Index dans une boucle for In [1]: speakers = ['Christian', 'Eric', 'Dave', 'Jordi'] In [2]: for i in range(len(speakers)): ...: print i, speakers[i]
  • 14. Index dans une boucle for In [1]: speakers = ['Christian', 'Eric', 'Dave', 'Jordi'] In [2]: for i in range(len(speakers)): ...: print i, speakers[i] In [3]: for i, speaker in enumerate(speakers): ...: print i, speaker
  • 15. range In [1]: for i in [0, 1, 2, 3, 4, 5]: ...: print i In [2]: for i in range(6): ...: print i
  • 16. range In [1]: for i in [0, 1, 2, 3, 4, 5]: ...: print i In [2]: for i in range(6): ...: print i In [3]: for i in xrange(6): ...: print i
  • 17. Compréhension à la portée de tous In [1]: a = [] In [2]: for i in xrange(10): ...: if not i % 2: ...: a.append(i) In [3]: a Out[3]: [0, 2, 4, 6, 8]
  • 18. Compréhension à la portée de tous In [1]: a = [] In [2]: for i in xrange(10): ...: if not i % 2: ...: a.append(i) In [3]: a Out[3]: [0, 2, 4, 6, 8] In [4]: a = [i for i in xrange(10) if not i % 2] In [5]: a Out[5]: [0, 2, 4, 6, 8]
  • 19. Almost all set In [1]: a = range(10000) + range(20000) + range(30000) In [2]: b = [] In [3]: for i in a: ...: if not i in b: ...: b.append(i)
  • 20. Almost all set In [1]: a = range(10000) + range(20000) + range(30000) In [2]: b = [] In [3]: for i in a: ...: if not i in b: ...: b.append(i) In [1]: a = range(10000) + range(20000) + range(30000) In [2]: b = list(set(a))
  • 22. Construire un dict à partir de listes In [1]: companies = ['sfl', 'nad'] In [2]: people = (['John', 'Jonathan', 'Jordi'], ['Christian']) In [3]: d = {} In [4]: for i, company in enumerate(companies): ...: d[company] = people[i] ...:
  • 23. Construire un dict à partir de listes In [1]: companies = ['sfl', 'nad'] In [2]: people = (['John', 'Jonathan', 'Jordi'], ['Christian']) In [3]: d = {} In [4]: for i, company in enumerate(companies): ...: d[company] = people[i] ...: In [5]: d = dict(izip(companies, people)) Out[5]: {'nad': ['Christian'], 'sfl': ['John', 'Jonathan', 'Jordi']}
  • 24. Boucles dans un dict In [1]: details = { 'sfl': ['John', 'Jonathan', 'Jordi'], 'nad': ['Christian'] } In [2]: for key in details.keys(): ...: print key
  • 25. Boucles dans un dict In [1]: details = { 'sfl': ['John', 'Jonathan', 'Jordi'], 'nad': ['Christian'] } In [2]: for key in details.keys(): ...: print key In [3]: for key in details: ...: print key
  • 26. Boucles dans un dict In [1]: details = { 'sfl': ['John', 'Jonathan', 'Jordi'], 'nad': ['Christian'] } In [2]: for key in details.keys(): ...: print key In [3]: for key in details: ...: print key In [4]: for key in details.iterkeys(): ...: print key
  • 27. Iteration mais pas tout le temps In [1]: for k in details.iterkeys(): ....: if k == 'sfl': ....: del details[k] RuntimeError: dictionary changed size during iteration
  • 28. Iteration mais pas tout le temps In [1]: for k in details.iterkeys(): ....: if k == 'sfl': ....: del details[k] RuntimeError: dictionary changed size during iteration In [2]: for k in details.keys(): ....: if k == 'sfl': ....: del details[k]
  • 29. Boucles dans un dict Autres outils d'itérations dans un dictionnaire: .keys() <-> .iterkeys() .values() <-> .itervalues() .items() <-> .iteritems()
  • 30. Remplir un dictionnaire In [1]: people = (['John', 'sfl'], ['Jonathan', 'sfl'], ['Jordi', 'sfl'], ['Christian', 'nad']) In [2]: d = {} In [3]: for p, company in peopls.iteritems(): ...: if company not in d: ...: d[company] = [] ...: d[company].append(p)
  • 31. Remplir un dictionnaire In [1]: people = (['John', 'sfl'], ['Jonathan', 'sfl'], ['Jordi', 'sfl'], ['Christian', 'nad']) In [2]: d = {} In [3]: for p, company in people.iteritems(): ...: if company not in d: ...: d[company] = [] ...: d[company].append(p) In [4]: for p, company in people.iteritems(): ....: d.setdefault(company, []).append(p)
  • 32. Remplir un dictionnaire In [5]: from collections import defaultdict In [6]: d = defaultdict(list) In [7]: for p, company in people.iteritems(): ....: d[company].append(p)
  • 34. In [1]: {'john': 'sfl', 'jonathan': 'sfl', 'jordi':'sfl' , 'christian':'nad'} Out[1]: {'christian': 'nad', 'john': 'sfl', 'jonathan': 'sfl', 'jordi': 'sfl'}
  • 35. OrderedDict In [1]: {'john': 'sfl', 'jonathan': 'sfl', 'jordi':'sfl' , 'christian':'nad'} Out[1]: {'christian': 'nad', 'john': 'sfl', 'jonathan': 'sfl', 'jordi': 'sfl'} In [2]: d = OrderedDict() In [3]: d['John'] = 'sfl' In [4]: d['Jonathan'] = 'sfl' In [5]: d['Jordi'] = 'sfl' In [6]: d['Christian'] = 'nad' In [7]: d Out[7]: OrderedDict([('John', 'sfl'), ('Jonathan', 'sfl'), ('Jordi', 'sfl'), ('Christian', 'nad')])
  • 36. namedtuple In [1]: get_points() Out[1]: [(65, 28, 45, 255, 255, 87), (255, 255, 87, 65, 28, 45)] In [2]: get_points() Out[2]: [Coord_color(x=65, y=28, z=45, r=255, g=255, b=87), Coord_color(x=255, y=255, z=87, r=65, g=28, b=45)]
  • 37. namedtuple In [1]: from collections import namedtuple In [2]: Coord_color = namedtuple('Coord_color', ['x', 'y', 'z', 'r', 'g', 'b']) In [3]: [Coord_color(65, 28, 45, 255, 255, 87), Coord_color(255, 255, 87, 65, 28, 45)] Out[3]: [Coord_color(x=65, y=28, z=45, r=255, g=255, b=87), Coord_color(x=255, y=255, z=87, r=65, g=28, b=45)] Namedtuple est une sous classe de tuple, lui donnant les mêmes méthodes qu'un tuple.