SlideShare une entreprise Scribd logo
1  sur  25
Eran Shlomo, Intel perceptual computing
eran.shlomo@intel.com ©
About me
Haifa IoT Ignition lab and IPP(Intel ingenuity partnership program) tech lead.
Intel Perceptual computing.
Python expert, started around 2009 with silicon analytics.
Focus on Data science and Machine learning in recent years (A lot of python).
About the PyCourse
Self driving course 
Just follow the slides, it is built both for self work as well as class work.
If you are not in class make sure to read the attached references and links.
If you are in class then read them later.
Why do you want to learn python ?
• Very fast prototyping.
• Cross platform.
• Rich libraries and capabilities.
• Good interactive/console experience.
• Fast engine (in script land)
• The leading language in AI world.
• More on The good, The bad and the ugly of python can be found here:
https://www.slideshare.net/EranShlomo/python-the-good-the-bad-and-the-ugly
Before we start
• Download and Install python 2.7
• Download, do not install :
• Download, python 3.5, pycharm, miniconda and google python classes.
Hello world
• Lets check we have python installed and good to go:
• Go to the folder you have extracted the course package zip, lets call it our working dir
• Open cmd in your working dir and check python is functional and in the right (2.7.12) version:
• If no python update your path, if version is incorrect change path variable order, you can check its
properly configured using where :
Lets make a simple hello world file and run it, create a file called hello.py and put in it a single
line printing hello:
• print "hello pycourse“
• Save and run it in cmd console:
• python hello.py
•
No python, in cmd type : set
PATH=C:Python27;%PATH%
Python versions
Python versions have significant importance, Python world struggles to move between
versions and there are many compatibility issues. Lets run our script on python 3:
• Install python 3.5.2
• Open cmd on working dir
• Set python 3 path to take priority :set PATH=<python 3 path>;%PATH%
• Run python - - version and make sure python version is right.
• Run our hello: fails …. Fix it:
• In python 3 print is no longer statement but function , many more differences…
• See more : http://sebastianraschka.com/Articles/2014_python_2_3_key_diff.html
Packaging
Python packing is pretty messy with a lot of ambiguity, today in python community the two leading
ones are:
• Easy_install – 2004, python first significant attempt to supply packaging mechanism
• Pip – 2008, alternative to easy_install and the common one as of today.
For more details : https://packaging.python.org/pip_easy_install/
There are two main aspect to packaging:
• I want to use packages in my project
• I want to package my project for others – out of this course scope.
Lets install a package, virtualenv:
• In command line, working dir (we are still in python 3) type: pip install virtualenv
Our python root
Being familiar with your python root structure is very important, many times
debug will take you there.
Lets look for our virtualenv package install:
• Go to python home, reminder where python will show you home.
• Under Lib you will find the packages and models (later on difference) that
comes with install. You will also find a folder called site-packages - our freshly
installed virtualenv package is there.
• Any packages we install will go there as well, which becomes pretty messy
after a while as different project requires different packages and versions.
Virtual environments
In order to allow developers easily develop between versions (many times you need to
work on many different version on the same machine) we have virtualenv package.
More details : http://docs.python-guide.org/en/latest/dev/virtualenvs/
This package allows you to create an isolated python environments, each with its own
dependencies and navigate between them. Lets create virtural environment:
• In our work dir type in console :virtualenv pycourse
• This creates virtual environment with the name pycourse, and installs base python +
setuptools into it, notice virtual env folder was created under sub dir pycourse
• Activate the virtualenv , in cmd type : .pycourseScriptsactivate
• And now deactivate it , in cmd type : .pycourseScriptsdeactivate
Module and packages
• Python has two main mechanisms for managing code blocks: modules and packages. Both
are almost the same conceptually, packages allows you to create more complex file structures
and name spaces:
• Module – single .py file
• Package – directory with __init__.py in it, can conatain sub packages.
Lets create an hello module and run it :
 create a file called hello_mod.py with the code, print ("hello pycourse module”)
 Create a subfolder called hello_pack, inside it create a file called __init__.py with the code,
print ("hello pycourse package ”)
 create a file called main.py with the following :
 Run main.py :
 Read more on the matter http://knowpapa.com/modpaclib-py/
Function
Lets make a function in hello mod:
• Python uses indentation as block, use 4 spaces for every block. Indentation rules can be found
here but keeping in mind 4 spaces in what usually is {}:
• Using Ide usually takes care of that for you easily.
• http://www.peachpit.com/articles/article.aspx?p=1312792&seqNum=3
Add function to hello_mod.py so it look like:
Lets run it, this time in console: run python in cmd, this will get you into interactive interpreter
mode. Now you can code directly into the interpreter. Import the module and call the function:
.
.
.
Time to IDE
Once we go into more coding IDE becomes extremely usefull, There are many IDEs out there, we will be using
JetBrains Pycharm, install it (download or take from course distribution).
Lets create a project with our code:
• File Create new project
• Put location of your work dir, choose interpreter of your python 3.5.2 install.
•
• Pycharm will warn on existing code, confirm it – it will create project with your code.
• Run main on ide, now run menu is empty :
• Right click main.py and click run main:
• And now run menu is active, with main as default run config:
• Put a breakpoint in the hello function and click debug :
• Debug button :
Classes
So we have an IDE working, pycharm is a great distribution of eclipse & pydev, so if you are
coming from JAVA you might feel at home pretty fast.
Python have two type of classes : classic and new style, always use the new style, notice the
pass keyword:
More on pass: https://www.tutorialspoint.com/python/python_pass_statement.htm
More on class stype differences:
http://stackoverflow.com/questions/54867/what-is-the-difference-between-old-style-and-new-style-
classes-in-python
Create an hello class inside hello_mod, new style as follows:
notice the self reference, it’s the python equivalent of this
Run main in pycharm and see in output console the result
CLASSIC
NEW
Wrapping point – short exercise
Build an image class rotator, Using the pillow package. Do the following:
• Install the Pillow package
• Build a class rotator with the following methods:
• Load – load an image to the rotator, parameter :im_path
• Rotate – rotate the image , parameter :rotation
• save– saves the currently rotated image, parameter :im_path
• Run the following code using your class and lena.jpg (inside project package, or choose
image of your choice) to get rotated images:
• Take the time to understand the code, first time we see loop and string formatting
PEPs
Python is developed and progress using PEPs, Python Enhancements Proposal
This is how community decides on language future and features, PEP0 contains the full
list: https://www.python.org/dev/peps/
As you are becoming python programmer, let go over PEP8:
• Authored by Guido, contains the “right syntax style” to python.
• Stick to PEP8
• PyCharm actually mark you where you got it wrong:
• Two violations here, import not on top, missing two blank lines.
• Nice feature : PyCharm contains auto fix under CodeReformat code
Read PEP20, we will get back to it later  - https://www.python.org/dev/peps/pep-0020/
Time to revisit our project folder
So while we are inside our nice and cozy IDE stuff is happening under the hood.
Important to stay in touch in the underlying project folder(especially if you manage joint
development and source control):
• So what do we have there now ?
• .idea folder – this is where pycharm stores it magic
• __pycache__ - this is where python caches the complied modules, read more here
http://stackoverflow.com/questions/2998215/if-python-is-interpreted-what-are-pyc-files
• Pycourse – the virtual env folder we used – Can you find PIL in there ?
• Our modules and package
• And a bunch of lena rotated images.
• Clean your work folder be fore we continue.
Google python classes
A great collection of python function you need to code, gradually covering
different python aspects while allowing you to test your code.
It contains some tutorials, Videos and exercises – we will focus on the exercises:
• More details @ https://developers.google.com/edu/python
The exercises have two parts:
• Basic, python modules that you need to “solve”
• Advanced, 3 small problems you need to code.
In the class we will focus on the basic, take as HW the advanced ones.
Setting our environment
• Create a new python project
• Add the basic subfolder into it
• Run string1.py, you have a bug fix it 
• Notice the print formatting in the files is different then the one we have seen so far. You can use both.
• The flow for each file:
• Module is running main(), what is the difference from what we did so far (calling main in the module)?
• Main calls test function with different inputs
• Each test is calling your function implementation, marking pass(OK)/fail (X) on console.
• You need to make it all pass , fail example :
• Lets start
String1.py
• You need to implement 4 strings manipulation functions:
• Each marked with letter (A,B,C,D).
• Each has instructions what is needed
• Each has a function signature
Solve all 4 functions, tips:
• Each module comes with reading page, read it.
• You can run it as many times as you want, work iteratively
• Google is your friend
• Use python console for fast experimenting
• Use debugger and break points and inspection.
• Combine both debugger and interactive –
Lets complete the rest
Complete rest of the modules, with the following order:
• String2
• List1, List2
• Wordcount
• If you got the time then go for mimic as well
Keep in mind every module has details in the google classes , strings details for
example :
https://developers.google.com/edu/python/strings
Recommendation for your next steps -
Recommended order
• Complete the advanced google execrcises
• Cover these shortly :docstrings, lambda functions, inheritance, getters and setter, decorators.
• Package your code using setuptools.
• Repeat the above using wheels.
• Learn about generators and iterators.
• Download and install miniconda package manager, install tensor flow using conda.
• Write multi-thread python program and see how fast it is:
• Network bounded – web page fetches.
• CPU bounded – count till 10^9
• Repeat the above using one of python multithread libs : twisted, gevent, async
• Learn how to use PYTHONPATH, write a pth file
• Install pip that requires build during install (like opencv)
• Write extension for python using c
• Use c extention from python
Just before we go – PEP20
The zen of python, use it as a mantra to an endless journey
Lets go over them.
1.Beautiful is better than ugly.
2.Explicit is better than implicit.
3.Simple is better than complex.
4.Complex is better than complicated.
5.Flat is better than nested.
6.Sparse is better than dense.
7.Readability counts.
8.Special cases aren't special enough to break the rules.
9.Although practicality beats purity.
10.Errors should never pass silently.
11.Unless explicitly silenced.
12.In the face of ambiguity, refuse the temptation to guess.
13.There should be one-- and preferably only one --obvious way to do it.
14.Although that way may not be obvious at first unless you're Dutch.
15.Now is better than never.
16.Although never is often better than *right* now.
17.If the implementation is hard to explain, it's a bad idea.
18.If the implementation is easy to explain, it may be a good idea.
19.Namespaces are one honking great idea -- let's do more of those!
eran.shlomo@intel.com

Contenu connexe

Tendances

A commercial open source project in Python
A commercial open source project in PythonA commercial open source project in Python
A commercial open source project in Pythonjbrendel
 
AmI 2017 - Python intermediate
AmI 2017 - Python intermediateAmI 2017 - Python intermediate
AmI 2017 - Python intermediateLuigi De Russis
 
Introduction to IPython & Notebook
Introduction to IPython & NotebookIntroduction to IPython & Notebook
Introduction to IPython & NotebookAreski Belaid
 
开源沙龙第一期 Python intro
开源沙龙第一期 Python intro开源沙龙第一期 Python intro
开源沙龙第一期 Python introfantasy zheng
 
Picademy #3 Python Picamera GPIO Workshop
Picademy #3 Python Picamera GPIO WorkshopPicademy #3 Python Picamera GPIO Workshop
Picademy #3 Python Picamera GPIO Workshopbennuttall
 
Learn raspberry pi programming with python
Learn raspberry pi programming with pythonLearn raspberry pi programming with python
Learn raspberry pi programming with pythonSANTIAGO PABLO ALBERTO
 
A quick overview of why to use and how to set up iPython notebooks for research
A quick overview of why to use and how to set up iPython notebooks for researchA quick overview of why to use and how to set up iPython notebooks for research
A quick overview of why to use and how to set up iPython notebooks for researchAdam Pah
 
Beginning nxt programming_workshop in Computer education robotics whoevgjvvvv...
Beginning nxt programming_workshop in Computer education robotics whoevgjvvvv...Beginning nxt programming_workshop in Computer education robotics whoevgjvvvv...
Beginning nxt programming_workshop in Computer education robotics whoevgjvvvv...OhSoAwesomeGirl
 
Parallel programming using python
Parallel programming using python Parallel programming using python
Parallel programming using python Samah Gad
 
Data Science Salon: Deep Learning as a Product @ Scribd
Data Science Salon: Deep Learning as a Product @ ScribdData Science Salon: Deep Learning as a Product @ Scribd
Data Science Salon: Deep Learning as a Product @ ScribdFormulatedby
 
Python setup for dummies
Python setup for dummiesPython setup for dummies
Python setup for dummiesRajesh Rajamani
 
How to Make a Chatbot in Python | Edureka
How to Make a Chatbot in Python | EdurekaHow to Make a Chatbot in Python | Edureka
How to Make a Chatbot in Python | EdurekaEdureka!
 
An Introduction To Python - Python, Print()
An Introduction To Python - Python, Print()An Introduction To Python - Python, Print()
An Introduction To Python - Python, Print()Blue Elephant Consulting
 
The magic of IPython Notebook
The magic of IPython NotebookThe magic of IPython Notebook
The magic of IPython NotebookAlexey Agapov
 
Thumbcoil: How we got here...
Thumbcoil: How we got here...Thumbcoil: How we got here...
Thumbcoil: How we got here...Jon-Carlos Rivera
 
Infrastructure as code might be literally impossible / Joe Domato (packageclo...
Infrastructure as code might be literally impossible / Joe Domato (packageclo...Infrastructure as code might be literally impossible / Joe Domato (packageclo...
Infrastructure as code might be literally impossible / Joe Domato (packageclo...Ontico
 
Parallel Programming in Python: Speeding up your analysis
Parallel Programming in Python: Speeding up your analysisParallel Programming in Python: Speeding up your analysis
Parallel Programming in Python: Speeding up your analysisManojit Nandi
 

Tendances (20)

Python intro for Plone users
Python intro for Plone usersPython intro for Plone users
Python intro for Plone users
 
A commercial open source project in Python
A commercial open source project in PythonA commercial open source project in Python
A commercial open source project in Python
 
AmI 2017 - Python intermediate
AmI 2017 - Python intermediateAmI 2017 - Python intermediate
AmI 2017 - Python intermediate
 
Introduction to IPython & Notebook
Introduction to IPython & NotebookIntroduction to IPython & Notebook
Introduction to IPython & Notebook
 
开源沙龙第一期 Python intro
开源沙龙第一期 Python intro开源沙龙第一期 Python intro
开源沙龙第一期 Python intro
 
Picademy #3 Python Picamera GPIO Workshop
Picademy #3 Python Picamera GPIO WorkshopPicademy #3 Python Picamera GPIO Workshop
Picademy #3 Python Picamera GPIO Workshop
 
Learn raspberry pi programming with python
Learn raspberry pi programming with pythonLearn raspberry pi programming with python
Learn raspberry pi programming with python
 
A quick overview of why to use and how to set up iPython notebooks for research
A quick overview of why to use and how to set up iPython notebooks for researchA quick overview of why to use and how to set up iPython notebooks for research
A quick overview of why to use and how to set up iPython notebooks for research
 
ZN-2015
ZN-2015ZN-2015
ZN-2015
 
Beginning nxt programming_workshop in Computer education robotics whoevgjvvvv...
Beginning nxt programming_workshop in Computer education robotics whoevgjvvvv...Beginning nxt programming_workshop in Computer education robotics whoevgjvvvv...
Beginning nxt programming_workshop in Computer education robotics whoevgjvvvv...
 
Parallel programming using python
Parallel programming using python Parallel programming using python
Parallel programming using python
 
LVPHP.org
LVPHP.orgLVPHP.org
LVPHP.org
 
Data Science Salon: Deep Learning as a Product @ Scribd
Data Science Salon: Deep Learning as a Product @ ScribdData Science Salon: Deep Learning as a Product @ Scribd
Data Science Salon: Deep Learning as a Product @ Scribd
 
Python setup for dummies
Python setup for dummiesPython setup for dummies
Python setup for dummies
 
How to Make a Chatbot in Python | Edureka
How to Make a Chatbot in Python | EdurekaHow to Make a Chatbot in Python | Edureka
How to Make a Chatbot in Python | Edureka
 
An Introduction To Python - Python, Print()
An Introduction To Python - Python, Print()An Introduction To Python - Python, Print()
An Introduction To Python - Python, Print()
 
The magic of IPython Notebook
The magic of IPython NotebookThe magic of IPython Notebook
The magic of IPython Notebook
 
Thumbcoil: How we got here...
Thumbcoil: How we got here...Thumbcoil: How we got here...
Thumbcoil: How we got here...
 
Infrastructure as code might be literally impossible / Joe Domato (packageclo...
Infrastructure as code might be literally impossible / Joe Domato (packageclo...Infrastructure as code might be literally impossible / Joe Domato (packageclo...
Infrastructure as code might be literally impossible / Joe Domato (packageclo...
 
Parallel Programming in Python: Speeding up your analysis
Parallel Programming in Python: Speeding up your analysisParallel Programming in Python: Speeding up your analysis
Parallel Programming in Python: Speeding up your analysis
 

En vedette

Actividad 6 Tablas y esquemas en Powerpoint
Actividad 6 Tablas y esquemas en PowerpointActividad 6 Tablas y esquemas en Powerpoint
Actividad 6 Tablas y esquemas en PowerpointEsteban Mendez Peña
 
Science1 اختبار علوم اوليمبياد
Science1 اختبار  علوم اوليمبيادScience1 اختبار  علوم اوليمبياد
Science1 اختبار علوم اوليمبيادMohamed Ragab Eltokhy
 
Math اختبار الرياضيات اولمبياد
Math اختبار الرياضيات اولمبيادMath اختبار الرياضيات اولمبياد
Math اختبار الرياضيات اولمبيادMohamed Ragab Eltokhy
 
Davison, kindra unit 9 assignment
Davison, kindra   unit 9 assignmentDavison, kindra   unit 9 assignment
Davison, kindra unit 9 assignmentK. D.
 
Plaquette huile alimentaire storage of edible oil
Plaquette huile alimentaire  storage of edible oilPlaquette huile alimentaire  storage of edible oil
Plaquette huile alimentaire storage of edible oilMohamed Larbi BEN YOUNES
 
SESION_CONFIANZA
SESION_CONFIANZASESION_CONFIANZA
SESION_CONFIANZAShanaiss
 
Imagine. Capture. Create. Interact
Imagine. Capture.Create. InteractImagine. Capture.Create. Interact
Imagine. Capture. Create. InteractEran Shlomo
 
Industrial internet of things
Industrial internet of thingsIndustrial internet of things
Industrial internet of thingsEran Shlomo
 
Internet of things - 2016 trends.
Internet of things - 2016 trends. Internet of things - 2016 trends.
Internet of things - 2016 trends. Eran Shlomo
 
Intel and Amazon - Powering your innovation together.
Intel and Amazon - Powering your innovation together. Intel and Amazon - Powering your innovation together.
Intel and Amazon - Powering your innovation together. Eran Shlomo
 
Manual de operador
Manual de operadorManual de operador
Manual de operadorlobosabio
 
Proyecto de construcción de un puente
Proyecto de construcción de un puenteProyecto de construcción de un puente
Proyecto de construcción de un puenteJuan Toledo González
 
Actividad 5 Elementos de las diapositivas
Actividad 5 Elementos de las diapositivasActividad 5 Elementos de las diapositivas
Actividad 5 Elementos de las diapositivasEsteban Mendez Peña
 
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
 
Fundamentos de la administracion
Fundamentos de la administracionFundamentos de la administracion
Fundamentos de la administracioncharin22
 
OOP Is More Then Cars and Dogs - Midwest PHP 2017
OOP Is More Then Cars and Dogs - Midwest PHP 2017OOP Is More Then Cars and Dogs - Midwest PHP 2017
OOP Is More Then Cars and Dogs - Midwest PHP 2017Chris Tankersley
 

En vedette (20)

Actividad 6 Tablas y esquemas en Powerpoint
Actividad 6 Tablas y esquemas en PowerpointActividad 6 Tablas y esquemas en Powerpoint
Actividad 6 Tablas y esquemas en Powerpoint
 
Actividad 2 Contaminación
Actividad 2 ContaminaciónActividad 2 Contaminación
Actividad 2 Contaminación
 
Actividad 4 Contaminación 2
Actividad 4 Contaminación 2Actividad 4 Contaminación 2
Actividad 4 Contaminación 2
 
Science1 اختبار علوم اوليمبياد
Science1 اختبار  علوم اوليمبيادScience1 اختبار  علوم اوليمبياد
Science1 اختبار علوم اوليمبياد
 
Math اختبار الرياضيات اولمبياد
Math اختبار الرياضيات اولمبيادMath اختبار الرياضيات اولمبياد
Math اختبار الرياضيات اولمبياد
 
Davison, kindra unit 9 assignment
Davison, kindra   unit 9 assignmentDavison, kindra   unit 9 assignment
Davison, kindra unit 9 assignment
 
Plaquette huile alimentaire storage of edible oil
Plaquette huile alimentaire  storage of edible oilPlaquette huile alimentaire  storage of edible oil
Plaquette huile alimentaire storage of edible oil
 
SESION_CONFIANZA
SESION_CONFIANZASESION_CONFIANZA
SESION_CONFIANZA
 
Proyecto ardillas explicación
Proyecto ardillas explicaciónProyecto ardillas explicación
Proyecto ardillas explicación
 
Imagine. Capture. Create. Interact
Imagine. Capture.Create. InteractImagine. Capture.Create. Interact
Imagine. Capture. Create. Interact
 
Industrial internet of things
Industrial internet of thingsIndustrial internet of things
Industrial internet of things
 
Internet of things - 2016 trends.
Internet of things - 2016 trends. Internet of things - 2016 trends.
Internet of things - 2016 trends.
 
Intel and Amazon - Powering your innovation together.
Intel and Amazon - Powering your innovation together. Intel and Amazon - Powering your innovation together.
Intel and Amazon - Powering your innovation together.
 
Manual de operador
Manual de operadorManual de operador
Manual de operador
 
Proyecto de construcción de un puente
Proyecto de construcción de un puenteProyecto de construcción de un puente
Proyecto de construcción de un puente
 
Actividad 8
Actividad 8 Actividad 8
Actividad 8
 
Actividad 5 Elementos de las diapositivas
Actividad 5 Elementos de las diapositivasActividad 5 Elementos de las diapositivas
Actividad 5 Elementos de las diapositivas
 
Advanced Python : Static and Class Methods
Advanced Python : Static and Class Methods Advanced Python : Static and Class Methods
Advanced Python : Static and Class Methods
 
Fundamentos de la administracion
Fundamentos de la administracionFundamentos de la administracion
Fundamentos de la administracion
 
OOP Is More Then Cars and Dogs - Midwest PHP 2017
OOP Is More Then Cars and Dogs - Midwest PHP 2017OOP Is More Then Cars and Dogs - Midwest PHP 2017
OOP Is More Then Cars and Dogs - Midwest PHP 2017
 

Similaire à PyCourse - Self driving python course

Introduction to the intermediate Python - v1.1
Introduction to the intermediate Python - v1.1Introduction to the intermediate Python - v1.1
Introduction to the intermediate Python - v1.1Andrei KUCHARAVY
 
Introduction to Python Unit -1 Part .pdf
Introduction to Python Unit -1 Part .pdfIntroduction to Python Unit -1 Part .pdf
Introduction to Python Unit -1 Part .pdfVaibhavKumarSinghkal
 
python intro and installation.pptx
python intro and installation.pptxpython intro and installation.pptx
python intro and installation.pptxadityakumawat625
 
Learn to Code with MIT App Inventor ( PDFDrive ).pdf
Learn to Code with MIT App Inventor ( PDFDrive ).pdfLearn to Code with MIT App Inventor ( PDFDrive ).pdf
Learn to Code with MIT App Inventor ( PDFDrive ).pdfNemoPalleschi
 
Py4 inf 01-intro
Py4 inf 01-introPy4 inf 01-intro
Py4 inf 01-introIshaq Ali
 
Python Requirements File How to Create Python requirements.txt
Python Requirements File How to Create Python requirements.txtPython Requirements File How to Create Python requirements.txt
Python Requirements File How to Create Python requirements.txtInexture Solutions
 
Introduction to python 3
Introduction to python 3Introduction to python 3
Introduction to python 3Youhei Sakurai
 
Introduction to python 3 2nd round
Introduction to python 3   2nd roundIntroduction to python 3   2nd round
Introduction to python 3 2nd roundYouhei Sakurai
 
Python Programming1.ppt
Python Programming1.pptPython Programming1.ppt
Python Programming1.pptRehnawilson1
 
Introduction to Python for Security Professionals
Introduction to Python for Security ProfessionalsIntroduction to Python for Security Professionals
Introduction to Python for Security ProfessionalsAndrew McNicol
 
Python-Yesterday Today Tomorrow(What's new?)
Python-Yesterday Today Tomorrow(What's new?)Python-Yesterday Today Tomorrow(What's new?)
Python-Yesterday Today Tomorrow(What's new?)Mohan Arumugam
 
Django Article V0
Django Article V0Django Article V0
Django Article V0Udi Bauman
 
Packaging perl (LPW2010)
Packaging perl (LPW2010)Packaging perl (LPW2010)
Packaging perl (LPW2010)p3castro
 
Programming Sessions KU Leuven - Session 01
Programming Sessions KU Leuven - Session 01Programming Sessions KU Leuven - Session 01
Programming Sessions KU Leuven - Session 01Rafael Camacho Dejay
 
Introduction to Python.pdf
Introduction to Python.pdfIntroduction to Python.pdf
Introduction to Python.pdfRahul Mogal
 
Scientist meets web dev: how Python became the language of data
Scientist meets web dev: how Python became the language of dataScientist meets web dev: how Python became the language of data
Scientist meets web dev: how Python became the language of dataGael Varoquaux
 

Similaire à PyCourse - Self driving python course (20)

Introduction to the intermediate Python - v1.1
Introduction to the intermediate Python - v1.1Introduction to the intermediate Python - v1.1
Introduction to the intermediate Python - v1.1
 
Python Tutorial Part 2
Python Tutorial Part 2Python Tutorial Part 2
Python Tutorial Part 2
 
Introduction to Python Unit -1 Part .pdf
Introduction to Python Unit -1 Part .pdfIntroduction to Python Unit -1 Part .pdf
Introduction to Python Unit -1 Part .pdf
 
Pythonpresent
PythonpresentPythonpresent
Pythonpresent
 
python intro and installation.pptx
python intro and installation.pptxpython intro and installation.pptx
python intro and installation.pptx
 
05 python.pdf
05 python.pdf05 python.pdf
05 python.pdf
 
Learn to Code with MIT App Inventor ( PDFDrive ).pdf
Learn to Code with MIT App Inventor ( PDFDrive ).pdfLearn to Code with MIT App Inventor ( PDFDrive ).pdf
Learn to Code with MIT App Inventor ( PDFDrive ).pdf
 
Py4 inf 01-intro
Py4 inf 01-introPy4 inf 01-intro
Py4 inf 01-intro
 
Python Requirements File How to Create Python requirements.txt
Python Requirements File How to Create Python requirements.txtPython Requirements File How to Create Python requirements.txt
Python Requirements File How to Create Python requirements.txt
 
Introduction to python 3
Introduction to python 3Introduction to python 3
Introduction to python 3
 
Introduction to python 3 2nd round
Introduction to python 3   2nd roundIntroduction to python 3   2nd round
Introduction to python 3 2nd round
 
Python Programming1.ppt
Python Programming1.pptPython Programming1.ppt
Python Programming1.ppt
 
Introduction to Python for Security Professionals
Introduction to Python for Security ProfessionalsIntroduction to Python for Security Professionals
Introduction to Python for Security Professionals
 
Python3handson
Python3handsonPython3handson
Python3handson
 
Python-Yesterday Today Tomorrow(What's new?)
Python-Yesterday Today Tomorrow(What's new?)Python-Yesterday Today Tomorrow(What's new?)
Python-Yesterday Today Tomorrow(What's new?)
 
Django Article V0
Django Article V0Django Article V0
Django Article V0
 
Packaging perl (LPW2010)
Packaging perl (LPW2010)Packaging perl (LPW2010)
Packaging perl (LPW2010)
 
Programming Sessions KU Leuven - Session 01
Programming Sessions KU Leuven - Session 01Programming Sessions KU Leuven - Session 01
Programming Sessions KU Leuven - Session 01
 
Introduction to Python.pdf
Introduction to Python.pdfIntroduction to Python.pdf
Introduction to Python.pdf
 
Scientist meets web dev: how Python became the language of data
Scientist meets web dev: how Python became the language of dataScientist meets web dev: how Python became the language of data
Scientist meets web dev: how Python became the language of data
 

Dernier

CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceBrainSell Technologies
 
How to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationHow to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationBradBedford3
 
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Matt Ray
 
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Natan Silnitsky
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEEVICTOR MAESTRE RAMIREZ
 
20240415 [Container Plumbing Days] Usernetes Gen2 - Kubernetes in Rootless Do...
20240415 [Container Plumbing Days] Usernetes Gen2 - Kubernetes in Rootless Do...20240415 [Container Plumbing Days] Usernetes Gen2 - Kubernetes in Rootless Do...
20240415 [Container Plumbing Days] Usernetes Gen2 - Kubernetes in Rootless Do...Akihiro Suda
 
Sending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdfSending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdf31events.com
 
SpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at RuntimeSpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at Runtimeandrehoraa
 
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company OdishaBalasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odishasmiwainfosol
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Andreas Granig
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmSujith Sukumaran
 
Introduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfIntroduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfFerryKemperman
 
PREDICTING RIVER WATER QUALITY ppt presentation
PREDICTING  RIVER  WATER QUALITY  ppt presentationPREDICTING  RIVER  WATER QUALITY  ppt presentation
PREDICTING RIVER WATER QUALITY ppt presentationvaddepallysandeep122
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfAlina Yurenko
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesPhilip Schwarz
 
UI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptxUI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptxAndreas Kunz
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureDinusha Kumarasiri
 
Cyber security and its impact on E commerce
Cyber security and its impact on E commerceCyber security and its impact on E commerce
Cyber security and its impact on E commercemanigoyal112
 
Comparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfComparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfDrew Moseley
 
Machine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringMachine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringHironori Washizaki
 

Dernier (20)

CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. Salesforce
 
How to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationHow to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion Application
 
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
 
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEE
 
20240415 [Container Plumbing Days] Usernetes Gen2 - Kubernetes in Rootless Do...
20240415 [Container Plumbing Days] Usernetes Gen2 - Kubernetes in Rootless Do...20240415 [Container Plumbing Days] Usernetes Gen2 - Kubernetes in Rootless Do...
20240415 [Container Plumbing Days] Usernetes Gen2 - Kubernetes in Rootless Do...
 
Sending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdfSending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdf
 
SpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at RuntimeSpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at Runtime
 
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company OdishaBalasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalm
 
Introduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfIntroduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdf
 
PREDICTING RIVER WATER QUALITY ppt presentation
PREDICTING  RIVER  WATER QUALITY  ppt presentationPREDICTING  RIVER  WATER QUALITY  ppt presentation
PREDICTING RIVER WATER QUALITY ppt presentation
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a series
 
UI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptxUI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptx
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with Azure
 
Cyber security and its impact on E commerce
Cyber security and its impact on E commerceCyber security and its impact on E commerce
Cyber security and its impact on E commerce
 
Comparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfComparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdf
 
Machine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringMachine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their Engineering
 

PyCourse - Self driving python course

  • 1. Eran Shlomo, Intel perceptual computing eran.shlomo@intel.com ©
  • 2. About me Haifa IoT Ignition lab and IPP(Intel ingenuity partnership program) tech lead. Intel Perceptual computing. Python expert, started around 2009 with silicon analytics. Focus on Data science and Machine learning in recent years (A lot of python).
  • 3. About the PyCourse Self driving course  Just follow the slides, it is built both for self work as well as class work. If you are not in class make sure to read the attached references and links. If you are in class then read them later.
  • 4. Why do you want to learn python ? • Very fast prototyping. • Cross platform. • Rich libraries and capabilities. • Good interactive/console experience. • Fast engine (in script land) • The leading language in AI world. • More on The good, The bad and the ugly of python can be found here: https://www.slideshare.net/EranShlomo/python-the-good-the-bad-and-the-ugly
  • 5. Before we start • Download and Install python 2.7 • Download, do not install : • Download, python 3.5, pycharm, miniconda and google python classes.
  • 6. Hello world • Lets check we have python installed and good to go: • Go to the folder you have extracted the course package zip, lets call it our working dir • Open cmd in your working dir and check python is functional and in the right (2.7.12) version: • If no python update your path, if version is incorrect change path variable order, you can check its properly configured using where : Lets make a simple hello world file and run it, create a file called hello.py and put in it a single line printing hello: • print "hello pycourse“ • Save and run it in cmd console: • python hello.py • No python, in cmd type : set PATH=C:Python27;%PATH%
  • 7. Python versions Python versions have significant importance, Python world struggles to move between versions and there are many compatibility issues. Lets run our script on python 3: • Install python 3.5.2 • Open cmd on working dir • Set python 3 path to take priority :set PATH=<python 3 path>;%PATH% • Run python - - version and make sure python version is right. • Run our hello: fails …. Fix it: • In python 3 print is no longer statement but function , many more differences… • See more : http://sebastianraschka.com/Articles/2014_python_2_3_key_diff.html
  • 8. Packaging Python packing is pretty messy with a lot of ambiguity, today in python community the two leading ones are: • Easy_install – 2004, python first significant attempt to supply packaging mechanism • Pip – 2008, alternative to easy_install and the common one as of today. For more details : https://packaging.python.org/pip_easy_install/ There are two main aspect to packaging: • I want to use packages in my project • I want to package my project for others – out of this course scope. Lets install a package, virtualenv: • In command line, working dir (we are still in python 3) type: pip install virtualenv
  • 9. Our python root Being familiar with your python root structure is very important, many times debug will take you there. Lets look for our virtualenv package install: • Go to python home, reminder where python will show you home. • Under Lib you will find the packages and models (later on difference) that comes with install. You will also find a folder called site-packages - our freshly installed virtualenv package is there. • Any packages we install will go there as well, which becomes pretty messy after a while as different project requires different packages and versions.
  • 10. Virtual environments In order to allow developers easily develop between versions (many times you need to work on many different version on the same machine) we have virtualenv package. More details : http://docs.python-guide.org/en/latest/dev/virtualenvs/ This package allows you to create an isolated python environments, each with its own dependencies and navigate between them. Lets create virtural environment: • In our work dir type in console :virtualenv pycourse • This creates virtual environment with the name pycourse, and installs base python + setuptools into it, notice virtual env folder was created under sub dir pycourse • Activate the virtualenv , in cmd type : .pycourseScriptsactivate • And now deactivate it , in cmd type : .pycourseScriptsdeactivate
  • 11. Module and packages • Python has two main mechanisms for managing code blocks: modules and packages. Both are almost the same conceptually, packages allows you to create more complex file structures and name spaces: • Module – single .py file • Package – directory with __init__.py in it, can conatain sub packages. Lets create an hello module and run it :  create a file called hello_mod.py with the code, print ("hello pycourse module”)  Create a subfolder called hello_pack, inside it create a file called __init__.py with the code, print ("hello pycourse package ”)  create a file called main.py with the following :  Run main.py :  Read more on the matter http://knowpapa.com/modpaclib-py/
  • 12. Function Lets make a function in hello mod: • Python uses indentation as block, use 4 spaces for every block. Indentation rules can be found here but keeping in mind 4 spaces in what usually is {}: • Using Ide usually takes care of that for you easily. • http://www.peachpit.com/articles/article.aspx?p=1312792&seqNum=3 Add function to hello_mod.py so it look like: Lets run it, this time in console: run python in cmd, this will get you into interactive interpreter mode. Now you can code directly into the interpreter. Import the module and call the function: . . .
  • 13. Time to IDE Once we go into more coding IDE becomes extremely usefull, There are many IDEs out there, we will be using JetBrains Pycharm, install it (download or take from course distribution). Lets create a project with our code: • File Create new project • Put location of your work dir, choose interpreter of your python 3.5.2 install. • • Pycharm will warn on existing code, confirm it – it will create project with your code. • Run main on ide, now run menu is empty : • Right click main.py and click run main: • And now run menu is active, with main as default run config: • Put a breakpoint in the hello function and click debug : • Debug button :
  • 14. Classes So we have an IDE working, pycharm is a great distribution of eclipse & pydev, so if you are coming from JAVA you might feel at home pretty fast. Python have two type of classes : classic and new style, always use the new style, notice the pass keyword: More on pass: https://www.tutorialspoint.com/python/python_pass_statement.htm More on class stype differences: http://stackoverflow.com/questions/54867/what-is-the-difference-between-old-style-and-new-style- classes-in-python Create an hello class inside hello_mod, new style as follows: notice the self reference, it’s the python equivalent of this Run main in pycharm and see in output console the result CLASSIC NEW
  • 15. Wrapping point – short exercise Build an image class rotator, Using the pillow package. Do the following: • Install the Pillow package • Build a class rotator with the following methods: • Load – load an image to the rotator, parameter :im_path • Rotate – rotate the image , parameter :rotation • save– saves the currently rotated image, parameter :im_path • Run the following code using your class and lena.jpg (inside project package, or choose image of your choice) to get rotated images: • Take the time to understand the code, first time we see loop and string formatting
  • 16. PEPs Python is developed and progress using PEPs, Python Enhancements Proposal This is how community decides on language future and features, PEP0 contains the full list: https://www.python.org/dev/peps/ As you are becoming python programmer, let go over PEP8: • Authored by Guido, contains the “right syntax style” to python. • Stick to PEP8 • PyCharm actually mark you where you got it wrong: • Two violations here, import not on top, missing two blank lines. • Nice feature : PyCharm contains auto fix under CodeReformat code Read PEP20, we will get back to it later  - https://www.python.org/dev/peps/pep-0020/
  • 17. Time to revisit our project folder So while we are inside our nice and cozy IDE stuff is happening under the hood. Important to stay in touch in the underlying project folder(especially if you manage joint development and source control): • So what do we have there now ? • .idea folder – this is where pycharm stores it magic • __pycache__ - this is where python caches the complied modules, read more here http://stackoverflow.com/questions/2998215/if-python-is-interpreted-what-are-pyc-files • Pycourse – the virtual env folder we used – Can you find PIL in there ? • Our modules and package • And a bunch of lena rotated images. • Clean your work folder be fore we continue.
  • 18. Google python classes A great collection of python function you need to code, gradually covering different python aspects while allowing you to test your code. It contains some tutorials, Videos and exercises – we will focus on the exercises: • More details @ https://developers.google.com/edu/python The exercises have two parts: • Basic, python modules that you need to “solve” • Advanced, 3 small problems you need to code. In the class we will focus on the basic, take as HW the advanced ones.
  • 19. Setting our environment • Create a new python project • Add the basic subfolder into it • Run string1.py, you have a bug fix it  • Notice the print formatting in the files is different then the one we have seen so far. You can use both. • The flow for each file: • Module is running main(), what is the difference from what we did so far (calling main in the module)? • Main calls test function with different inputs • Each test is calling your function implementation, marking pass(OK)/fail (X) on console. • You need to make it all pass , fail example : • Lets start
  • 20. String1.py • You need to implement 4 strings manipulation functions: • Each marked with letter (A,B,C,D). • Each has instructions what is needed • Each has a function signature Solve all 4 functions, tips: • Each module comes with reading page, read it. • You can run it as many times as you want, work iteratively • Google is your friend • Use python console for fast experimenting • Use debugger and break points and inspection. • Combine both debugger and interactive –
  • 21. Lets complete the rest Complete rest of the modules, with the following order: • String2 • List1, List2 • Wordcount • If you got the time then go for mimic as well Keep in mind every module has details in the google classes , strings details for example : https://developers.google.com/edu/python/strings
  • 22. Recommendation for your next steps - Recommended order • Complete the advanced google execrcises • Cover these shortly :docstrings, lambda functions, inheritance, getters and setter, decorators. • Package your code using setuptools. • Repeat the above using wheels. • Learn about generators and iterators. • Download and install miniconda package manager, install tensor flow using conda. • Write multi-thread python program and see how fast it is: • Network bounded – web page fetches. • CPU bounded – count till 10^9 • Repeat the above using one of python multithread libs : twisted, gevent, async • Learn how to use PYTHONPATH, write a pth file • Install pip that requires build during install (like opencv) • Write extension for python using c • Use c extention from python
  • 23. Just before we go – PEP20 The zen of python, use it as a mantra to an endless journey Lets go over them.
  • 24. 1.Beautiful is better than ugly. 2.Explicit is better than implicit. 3.Simple is better than complex. 4.Complex is better than complicated. 5.Flat is better than nested. 6.Sparse is better than dense. 7.Readability counts. 8.Special cases aren't special enough to break the rules. 9.Although practicality beats purity. 10.Errors should never pass silently. 11.Unless explicitly silenced. 12.In the face of ambiguity, refuse the temptation to guess. 13.There should be one-- and preferably only one --obvious way to do it. 14.Although that way may not be obvious at first unless you're Dutch. 15.Now is better than never. 16.Although never is often better than *right* now. 17.If the implementation is hard to explain, it's a bad idea. 18.If the implementation is easy to explain, it may be a good idea. 19.Namespaces are one honking great idea -- let's do more of those!