Vous avez reçu un message "Your GitLab account has been locked ..." ? Pas d'inquiétude : lisez cet article https://docs.gricad-pages.univ-grenoble-alpes.fr/help/unlock/

Commit 63b65ff0 authored by Loic Huder's avatar Loic Huder
Browse files

Merge branch 'revert-0db3ea91' into 'master'

Revert "Merge remote-tracking branch 'origin/master'"

See merge request !1
parents 0db3ea91 099d1b9b
......@@ -12,7 +12,7 @@
"\n",
"**A training to acquire strong basis in Python to use it efficiently**\n",
"\n",
"Pierre Augier (LEGI), Cyrille Bonamy (LEGI), Eric Maldonado (Irstea), Franck Thollard (ISTerre), Christophe Picard (LJK), Loïc Huder (ISTerre)\n"
"Pierre Augier (LEGI), Cyrille Bonamy (LEGI), Eric Maldonado (Irstea), Franck Thollard (ISTERRE), Christophe Picard (LJK)\n"
]
},
{
......@@ -86,7 +86,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.2"
"version": "3.6.2"
}
},
"nbformat": 4,
......
......@@ -137,7 +137,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.2"
"version": "3.5.4"
}
},
"nbformat": 4,
......
......@@ -12,7 +12,7 @@
"\n",
"**A training to acquire strong basis in Python to use it efficiently**\n",
"\n",
"Pierre Augier (LEGI), Cyrille Bonamy (LEGI), Eric Maldonado (Irstea), Franck Thollard (ISTerre), Christophe Picard (LJK) Loïc Huder (ISTerre)\n",
"Pierre Augier (LEGI), Cyrille Bonamy (LEGI), Eric Maldonado (Irstea), Franck Thollard (ISTERRE), Christophe Picard (LJK)\n",
"\n",
"# First steps\n",
"\n",
......@@ -136,7 +136,7 @@
"python3 pyfiles/helloworld.py\n",
"```\n",
"\n",
"(`cat` is a Unix command that print the content of a text file.)"
"(`cat` is a Unix command to show the content of a text file.)"
]
},
{
......@@ -182,7 +182,7 @@
{
"data": {
"text/plain": [
"0.75"
"7"
]
},
"execution_count": 1,
......@@ -191,7 +191,7 @@
}
],
"source": [
"3 / 4"
"3 + 4"
]
},
{
......@@ -276,7 +276,7 @@
"\n",
"- it is very important to use a good editor to code in Python (for example spyder, emacs or vi with [a good setup](https://bitbucket.org/fluiddyn/fluid_emacs.d)).\n",
"\n",
"- a good modern open-source editor: [Visual Studio Code] (https://code.visualstudio.com/docs/languages/python)."
"- a good modern open-source editor: [Visual Studio Code](https://code.visualstudio.com/docs/languages/python)."
]
},
{
......@@ -312,7 +312,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.2"
"version": "3.6.6"
}
},
"nbformat": 4,
......
......@@ -12,9 +12,7 @@
"\n",
"**A training to acquire strong basis in Python to use it efficiently**\n",
"\n",
"Pierre Augier (LEGI), Cyrille Bonamy (LEGI), Eric Maldonado (Irstea), Franck Thollard (ISTerre), Christophe Picard (LJK),\n",
" Loïc Huder (ISTerre)\n",
" \n",
"Pierre Augier (LEGI), Cyrille Bonamy (LEGI), Eric Maldonado (Irstea), Franck Thollard (ISTERRE), Christophe Picard (LJK)\n",
"\n",
"# Characteristics of the Python language"
]
......@@ -447,7 +445,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.2"
"version": "3.6.6"
}
},
"nbformat": 4,
......
......@@ -12,7 +12,7 @@
"\n",
"**A training to acquire strong basis in Python to use it efficiently**\n",
"\n",
"Pierre Augier (LEGI), Cyrille Bonamy (LEGI), Eric Maldonado (Irstea), Franck Thollard (ISTerre), Christophe Picard (LJK), Loïc Huder (ISTerre)\n",
"Pierre Augier (LEGI), Cyrille Bonamy (LEGI), Eric Maldonado (Irstea), Franck Thollard (ISTERRE), Christophe Picard (LJK)\n",
"\n",
"# More standard types and basic statements"
]
......@@ -765,7 +765,7 @@
"\n",
"Strings are immutable **[\"sequences\"](https://docs.python.org/3/library/stdtypes.html)**.\n",
"\n",
"- lookup"
"- loopup"
]
},
{
......@@ -1919,7 +1919,7 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": 61,
"metadata": {},
"outputs": [
{
......@@ -1937,7 +1937,7 @@
"while i < len(numbers):\n",
" local_sum = local_sum + numbers[i]\n",
" i = i+1\n",
"avg = local_sum / len(numbers)\n",
"avg = local_sum /len(numbers)\n",
"print(avg)"
]
},
......@@ -2125,15 +2125,15 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 67,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"integer remove from the list: 3\n",
"shuffled list: [13, 16, 6, 10, 17, 19, 4, 2, 5, 9, 0, 7, 11, 12, 14, 8, 1, 15, 18]\n"
"integer remove from the list: 7\n",
"shuffled list: [1, 12, 13, 3, 8, 19, 9, 14, 5, 17, 18, 6, 11, 15, 10, 2, 16, 4, 0]\n"
]
}
],
......@@ -2172,16 +2172,16 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 68,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[13, 16, 6, 10, 17, 19, 4, 2, 5, 9, 0, 7, 11, 12, 14, 8, 1, 15, 18]\n",
"[0, 1, 2, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]\n",
"missing 3\n"
"[1, 12, 13, 3, 8, 19, 9, 14, 5, 17, 18, 6, 11, 15, 10, 2, 16, 4, 0]\n",
"[0, 1, 2, 3, 4, 5, 6, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]\n",
"missing 7\n"
]
}
],
......@@ -2203,14 +2203,14 @@
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": 69,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"missing 3\n"
"missing 7\n"
]
}
],
......@@ -2222,27 +2222,6 @@
"print(\"missing \", elem)"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"missing 3\n"
]
}
],
"source": [
"# another solution\n",
"actual_sum = sum(l)\n",
"len_l = len(l)\n",
"original_sum = (len_l + 1) * (len_l) // 2\n",
"print(\"missing \", original_sum - actual_sum)"
]
},
{
"cell_type": "markdown",
"metadata": {
......@@ -2376,18 +2355,15 @@
"source": [
"### Do it yourself: \n",
"\n",
"For each line of this string, append a variable of correct type in a list (i.e. \"hello\" should stay hello, \n",
"2 should become an int and 1.5 a float). Do it by catching errors.\n",
"\n",
"**Hints:** \n",
" - int(\"a\") and float(\"a\") raise ValueError\n",
" - the above str_variable can be split using \"\\n\""
"For each line of this string, append a variable of correct type in a list. Do it by catching errors."
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"str_variables = \"\"\"hello\n",
......@@ -2459,7 +2435,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.2"
"version": "3.6.6"
}
},
"nbformat": 4,
......
......@@ -12,7 +12,7 @@
"\n",
"**A training to acquire strong basis in Python to use it efficiently**\n",
"\n",
"Pierre Augier (LEGI), Cyrille Bonamy (LEGI), Eric Maldonado (Irstea), Franck Thollard (ISTerre), Christophe Picard (LJK), Loïc Huder (ISTerre)\n",
"Pierre Augier (LEGI), Cyrille Bonamy (LEGI), Eric Maldonado (Irstea), Franck Thollard (ISTERRE), Christophe Picard (LJK)\n",
"\n",
"# Functions\n",
"\n",
......@@ -38,7 +38,7 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": 1,
"metadata": {},
"outputs": [
{
......@@ -54,11 +54,9 @@
],
"source": [
"def print_hello():\n",
" \"hello printer\"\n",
" print('hello')\n",
"\n",
"def myprint(s):\n",
" \"my hello printer\"\n",
" print('I print', s)\n",
" \n",
"# function calls\n",
......@@ -79,15 +77,15 @@
"## Simple function definitions and calls\n",
"\n",
"- The first statement of a function can be the documentation string of the function, also called \"docstring\".\n",
"- The statement `return [expression]` exits a function, optionally passing back an expression to the caller. No return statement or a return statement with no arguments is the same as `return None`.\n",
"\n",
"(Note: Wikipedia about duck typing: https://fr.wikipedia.org/wiki/Duck_typing)\n"
"- The statement `return [expression]` exits a function, optionally passing back an expression to the caller. No return statement or a return statement with no arguments is the same as `return None`."
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"execution_count": 2,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"def add(arg0, arg1):\n",
......@@ -1094,7 +1092,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.2"
"version": "3.6.6"
}
},
"nbformat": 4,
......
......@@ -3,6 +3,8 @@
{
"cell_type": "markdown",
"metadata": {
"deletable": true,
"editable": true,
"slideshow": {
"slide_type": "slide"
}
......@@ -12,7 +14,7 @@
"\n",
"**A training to acquire strong basis in Python to use it efficiently**\n",
"\n",
"Pierre Augier (LEGI), Cyrille Bonamy (LEGI), Eric Maldonado (Irstea), Franck Thollard (ISTerre), Christophe Picard (LJK), Loïc Huder (ISTerre)\n",
"Pierre Augier (LEGI), Cyrille Bonamy (LEGI), Eric Maldonado (Irstea), Franck Thollard (ISTERRE), Christophe Picard (LJK)\n",
"\n",
"# Read / write files"
]
......@@ -20,6 +22,8 @@
{
"cell_type": "markdown",
"metadata": {
"deletable": true,
"editable": true,
"slideshow": {
"slide_type": "slide"
}
......@@ -35,7 +39,11 @@
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"metadata": {
"collapsed": false,
"deletable": true,
"editable": true
},
"outputs": [
{
"name": "stdout",
......@@ -60,22 +68,8 @@
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"But what if something weird happens when the file is open (e.g. a division by O) ? \n",
"\n",
"-> Exception is raised that could be catch and run some code that is not aware of the opening \n",
"file.\n",
"\n",
"-> The file remains open "
]
},
{
"cell_type": "markdown",
"metadata": {
"deletable": true,
"editable": true,
"slideshow": {
"slide_type": "subslide"
}
......@@ -113,6 +107,7 @@
{
"cell_type": "markdown",
"metadata": {
"editable": true,
"slideshow": {
"slide_type": "subslide"
}
......@@ -124,7 +119,11 @@
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"metadata": {
"collapsed": false,
"deletable": true,
"editable": true
},
"outputs": [
{
"name": "stdout",
......@@ -154,7 +153,10 @@
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"metadata": {
"collapsed": false,
"editable": true
},
"outputs": [
{
"name": "stdout",
......@@ -177,6 +179,8 @@
{
"cell_type": "markdown",
"metadata": {
"deletable": true,
"editable": true,
"slideshow": {
"slide_type": "subslide"
}
......@@ -188,7 +192,11 @@
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"metadata": {
"collapsed": false,
"deletable": true,
"editable": true
},
"outputs": [
{
"name": "stdout",
......@@ -218,7 +226,11 @@
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"metadata": {
"collapsed": false,
"deletable": true,
"editable": true
},
"outputs": [
{
"name": "stdout",
......@@ -240,7 +252,10 @@
},
{
"cell_type": "markdown",
"metadata": {},
"metadata": {
"deletable": true,
"editable": true
},
"source": [
"Remark: difference `write` and `print`."
]
......@@ -248,6 +263,8 @@
{
"cell_type": "markdown",
"metadata": {
"deletable": true,
"editable": true,
"slideshow": {
"slide_type": "subslide"
}
......@@ -261,7 +278,11 @@
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"metadata": {
"collapsed": false,
"deletable": true,
"editable": true
},
"outputs": [],
"source": [
"with open('/tmp/test', 'wb') as file:\n",
......@@ -270,7 +291,10 @@
},
{
"cell_type": "markdown",
"metadata": {},
"metadata": {
"deletable": true,
"editable": true
},
"source": [
"Remarks: \n",
"\n",
......@@ -297,7 +321,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.2"
"version": "3.6.6"
}
},
"nbformat": 4,
......
......@@ -3,6 +3,8 @@
{
"cell_type": "markdown",
"metadata": {
"deletable": true,
"editable": true,
"slideshow": {
"slide_type": "slide"
}
......@@ -12,7 +14,7 @@
"\n",
"**A training to acquire strong basis in Python to use it efficiently**\n",
"\n",
"Pierre Augier (LEGI), Cyrille Bonamy (LEGI), Eric Maldonado (Irstea), Franck Thollard (ISTerre), Christophe Picard (LJK), Loïc Huder (ISTerre)\n",
"Pierre Augier (LEGI), Cyrille Bonamy (LEGI), Eric Maldonado (Irstea), Franck Thollard (ISTERRE), Christophe Picard (LJK)\n",
"\n",
"## Practical session 0\n",
"\n",
......@@ -22,6 +24,8 @@
{
"cell_type": "markdown",
"metadata": {
"deletable": true,
"editable": true,
"slideshow": {
"slide_type": "subslide"
}
......@@ -34,7 +38,7 @@
"- write code in scripts,\n",
"- use ipython and execute Python programs with the command python3,\n",
"- use objects of simple types (numbers, str, list, etc.),\n",
"- index and slice,\n",
"- indexing, slicing,\n",
"- use loops and conditions,\n",
"- try, except,\n",
"- read and write in text files.\n",
......@@ -49,6 +53,8 @@
{
"cell_type": "markdown",
"metadata": {
"deletable": true,
"editable": true,
"slideshow": {
"slide_type": "slide"
}
......@@ -84,6 +90,8 @@
{
"cell_type": "markdown",
"metadata": {
"deletable": true,
"editable": true,
"slideshow": {
"slide_type": "subslide"
}
......@@ -100,7 +108,9 @@
"cell_type": "code",
"execution_count": 3,
"metadata": {
"collapsed": true
"collapsed": true,
"deletable": true,
"editable": true
},
"outputs": [],
"source": [
......@@ -117,6 +127,8 @@
{
"cell_type": "markdown",
"metadata": {
"deletable": true,
"editable": true,
"slideshow": {
"slide_type": "subslide"
}
......@@ -134,9 +146,9 @@
"file = \"../data/file0.1.txt\"\n",
"nb = 78 ; sum = 42.46 ; avg = 1.84 \n",
"file = \"../data/file0.2.txt\"\n",
"nb = 100 ; sum = 53.29 ; avg = 0.53\n",
"nb = 100 ; sum = 53.29 ; avg = 1.88 \n",
"file = \"../data/file0.3.txt\"\n",
"nb = 25 ; sum = 12.72 ; avg = 0.51 \n",
"nb = 25 ; sum = 12.72 ; avg = 1.97 \n",
"# total over all files:\n",
"nb = 203 ; sum = 108.47 ; avg = 0.53\n",
"```"
......@@ -145,6 +157,8 @@
{
"cell_type": "markdown",
"metadata": {
"deletable": true,
"editable": true,
"slideshow": {
"slide_type": "slide"
}
......@@ -170,6 +184,8 @@
{
"cell_type": "markdown",
"metadata": {
"deletable": true,
"editable": true,
"slideshow": {
"slide_type": "subslide"
}
......@@ -201,6 +217,8 @@
{
"cell_type": "markdown",
"metadata": {
"deletable": true,
"editable": true,
"slideshow": {
"slide_type": "slide"
}
......@@ -237,6 +255,8 @@
{
"cell_type": "markdown",
"metadata": {
"deletable": true,
"editable": true,
"slideshow": {
"slide_type": "subslide"
}
......@@ -256,7 +276,9 @@
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": true
"collapsed": true,
"deletable": true,
"editable": true
},
"outputs": [],
"source": [
......@@ -281,7 +303,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.2"
"version": "3.6.2"
}
},
"nbformat": 4,
......
......@@ -3,6 +3,8 @@
{
"cell_type": "markdown",
"metadata": {
"deletable": true,
"editable": true,
"slideshow": {
"slide_type": "slide"
}
......@@ -12,7 +14,7 @@
"\n",
"**A training to acquire strong basis in Python to use it efficiently**\n",
"\n",
"Pierre Augier (LEGI), Cyrille Bonamy (LEGI), Eric Maldonado (Irstea), Franck Thollard (ISTerre), Christophe Picard (LJK), Loïc Huder (ISTerre)\n",
"Pierre Augier (LEGI), Cyrille Bonamy (LEGI), Eric Maldonado (Irstea), Franck Thollard (ISTERRE), Christophe Picard (LJK)\n",
"\n",
"# Modules, `import` statement and the standard library"
]
......@@ -20,6 +22,8 @@
{
"cell_type": "markdown",
"metadata": {
"deletable": true,
"editable": true,
"slideshow": {
"slide_type": "slide"
}
......@@ -42,6 +46,8 @@
{
"cell_type": "markdown",
"metadata": {
"deletable": true,
"editable": true,
"slideshow": {
"slide_type": "slide"
}
......@@ -56,7 +62,11 @@
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},