README.md 2.4 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# 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

20
21
# Why python ?

22
## Pros
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40

 - flexibility (not typed)
 - concision of the syntax
    ```python
    print('Hello world')
    ```
    
    ```c++
    #include <iostream>

    int main() 
    {
        std::cout << "Hello, World!";
        return 0;
    }
    ```
 - good learning curve
 - lots of resources
41
 - python console makes it easy to test things
42
43
44
45
46
47
 
## Cons

 - flexibility (not typed)
 - slow (interpreted language)
 - not good for multi-processor/multi-core work
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77

# 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](https://docs.python.org/3/tutorial/datastructures.html#list-comprehensions).

## B - Zip

`zip` is a simple but efficient function, that can simplify lot of code, reducing the use of intermediate variables.

[doc](https://docs.python.org/3/library/functions.html#zip)

## 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.
78
79
80
81
82
83
84
85

# 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.