def filter(values, max):
results = list()
for val in values:
if val < max:
results.append(val)
return results
class Test(object):
def do_something(self, a, b):
return a + b
Easy to learn, read & write
“I came to Python (...) because it was the best pseudocode. Python has the edge (with a large number of students) when the main goal is communication, not programming per se.”
“Python has the philosophy of making sensible compromises that make the easy things very easy, and don't preclude too many hard things.” Norvig
only in two ends.
First step
get python
get pip & venv
get ipython
Experiment & read a lot of code
Communicate
Semantics
everything is an object
only names, values
runtime is your friend (repl, no compilation)
Fractal & setup
Let's do it!
requirements.txt
setup
fractal
best practice
Web Stuff
a bit of http
wsgi
flask, bottle, django
sqlalchemy
celery
Flask in a slide
from flask import Flask
app = Flask(__name__)
@app.route('/')
def index():
return "hello world"
if __name__ == "__main__":
app.run(host="0.0.0.0", debug=True)
Par rapport aux autres languages ?
JS : celui qui s'en fout
arguments
types
context (this)
no class, no module, etc.
C#/Java : l'administration soviétique
utile dans des projets critiques
mais lent dans la conception, car verbeux & contraignant
Python :
bon équilibre entre les deux
fortement typé
mais dynamique
la preuve : très gros projets (django, openstack, etc)
In [48]: "1.0" + 1
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
/home/lionel/<ipython-input-48-6f0b01de9b7a> in <module>()
----> 1 "1.0" + 1
TypeError: cannot concatenate 'str' and 'int' objects