Abstract
Formation made by Mathieu Béligon in Oct 2019 for the Computer Vision Team, of the Robomaster division of Polystar.
This is not a formation to learn python from scratch, you should know the python syntax to be able to understand it.
Some history
- 1980: language conception
- 1994: python 1 release (lambda, map, …)
- 2000: python 2 release (list comprehension, garbage collector)
- 2008: python 3 release (major code refactor)
- 2015: 3.5
- 2016: 3.6
- 2018: 3.7 - we use that one
- 2019: 3.8 - new of this month
- to come: python 3.9 https://docs.python.org/3.9/whatsnew/3.9.html
- to come ? python 4.0
Why python ?
Pros
-
flexibility (not typed)
-
concision of the syntax
print('Hello world')
#include <iostream> int main() { std::cout << "Hello, World!"; return 0; }
-
good learning curve
-
lots of resources
-
python console makes it easy to test things
Cons
- flexibility (not typed)
- slow (interpreted language)
- not good for multi-processor/multi-core work
Content
We present here some modules and functions from the standard library, no dependency is required.
For the D/dataclasses chapter, python37 or more is required.
A - List comprehension
The list comprehension, (introduced in Python2 in 2000) is a powerful tool that python offers.
Using list comprehension instead of for loops when possible is a pythonic and faster way to code.
B - Zip
zip
is a simple but efficient function, that can simplify lot of code, reducing the use of intermediate variables.
C - pathlib
(python34 or more required)
pathlib
is a quite recent module (2014) in the standard library that provide easy ways of manipulating files and directories.
D - dataclasses
(python37 or more required)
The new dataclass
decorator (2018) helps you to drastically reduce the amount of code you write. It also helps you to avoid code deduplication.
The code
To run the code in pycharm, you should mark the [./01-python] directory as source root.
(right click on 01-python
on the left nav > Mark Directory as ...
> Sources Root
)
This way, pycharm will add the directory to the list of packages it can access, and know where to find the includes.