Commit 5342e919 authored by paugier's avatar paugier
Browse files

Solve problem with reveal.js

parent 2f31e2af
syntax: glob
*.pyd*
*.pyc
*~
......@@ -13,4 +11,5 @@ ipynb/*.slides.html
**/*.egg-info/
ipynb/index.html
\ No newline at end of file
ipynb/index.html
.vscode
\ No newline at end of file
......@@ -37,7 +37,7 @@ ipynb/index.html: ipynb/index.rst
cd $(IPYNBDIR) && rst2html5 index.rst > index.html
%.slides.html: %.ipynb ipynb/slides_reveal_wide.tpl
jupyter-nbconvert $< --to slides --template ipynb/slides_reveal_wide.tpl
jupyter-nbconvert $< --reveal-prefix='./reveal.js' --to slides --template ipynb/slides_reveal_wide.tpl
presentations: $(IPYNBPRES) ipynb/index.html
......
......@@ -9,12 +9,10 @@ To display and/or modify the presentations, use the Makefile. See::
make help
Repositories
------------
Repository
----------
The old repository is https://sourcesup.renater.fr/projects/py-training-uga/
We now use a repository hosted in the Gitlab of UGA:
The repository hosted in the Gitlab of UGA:
https://gricad-gitlab.univ-grenoble-alpes.fr/python-uga
- Clone the repository with Git with https::
......@@ -40,5 +38,4 @@ Authors
-------
Pierre Augier (LEGI), Cyrille Bonamy (LEGI), Eric Maldonado (Irstea), Franck
Thollard (ISTERRE), Christophe Picard (LJK)
Thollard (ISTERRE), Christophe Picard (LJK), Loïc Huder (ISTerre)
......@@ -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), Loïc Huder (ISTerre)\n",
"\n",
"# First steps\n",
"\n",
......@@ -274,9 +274,7 @@
"\n",
"Remarks: \n",
"\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)."
"- 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), or [Visual Studio Code](https://code.visualstudio.com/docs/languages/python))."
]
},
{
......@@ -312,7 +310,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.6"
"version": "3.7.2"
}
},
"nbformat": 4,
......
%% Cell type:markdown id: tags:
# Python training UGA 2017
**A training to acquire strong basis in Python to use it efficiently**
Pierre Augier (LEGI), Cyrille Bonamy (LEGI), Eric Maldonado (Irstea), Franck Thollard (ISTerre), Christophe Picard (LJK) Loïc Huder (ISTerre)
Pierre Augier (LEGI), Cyrille Bonamy (LEGI), Eric Maldonado (Irstea), Franck Thollard (ISTerre), Christophe Picard (LJK), Loïc Huder (ISTerre)
# First steps
Repository containing the source of this training:
`https://gricad-gitlab.univ-grenoble-alpes.fr/python-uga/py-training-2017`
%% Cell type:markdown id: tags:
## Why Python ?
- A very nice and well-thought programming language.
- **Generalist**: good for several applications, [used with success in many fields](http://brochure.getpython.info/).
- For academic purposes (teaching, research): **great scientific ecosystem**.
%% Cell type:markdown id: tags:
## Python: a language, an interpreter
Python is a programming language.
It is first an **interpreted** language (like Bash, Matlab, and in contrast with Fortran, C or C++), so we need an interpreter, i.e. a binary parsing Python code and running computer instructions.
Open a terminal. There are usually different python commands: `python`, `python2` and `python3`.
%% Cell type:markdown id: tags:
### Remark Python 2 / Python 3
2 languages, 2 interpreters, 2 commands
%% Cell type:markdown id: tags:
## Python distributions
- On Linux, there are the system python binaries.
- On Windows, Mac (and Linux), you can install and use
* https://www.python.org/downloads/
* [Anaconda or Miniconda](https://www.continuum.io/downloads)
([advice on how to install a good scientific Python environment](http://fluiddyn.readthedocs.io/en/latest/get_good_Python_env.html))
- In some systems (cluster), there are modules:
```bash
module load python
```
%% Cell type:markdown id: tags:
### Do it yourself: personal work
Download the repository of this training (you need one of the programs `git` or `mercurial`). On Unix machines, use the commands:
```bash
git clone https://gricad-gitlab.univ-grenoble-alpes.fr/python-uga/py-training-2017.git
# or with Mercurial:
# hg clone https://gricad-gitlab.univ-grenoble-alpes.fr/python-uga/py-training-2017.git
cd py-training-2017
cat README.rst
make help
```
Warning: `cat` and `make` are Unix commands...
%% Cell type:markdown id: tags:
### Do it yourself: execute a script with the command `python3`
Run a script with `python3` (pyfiles/helloworld.py is *just* a text file):
```bash
cat pyfiles/helloworld.py
python3 pyfiles/helloworld.py
```
(`cat` is a Unix command that print the content of a text file.)
%% Cell type:markdown id: tags:
### Do it yourself: work interactively with [ipython](https://ipython.org/)
The command `ipython3` launch the program [ipython](https://ipython.org/), which is used for interactive python.
- In ipython, you can execute a first interactive instruction:
%% Cell type:code id: tags:
``` python
2 + 2
```
%%%% Output: execute_result
4
%% Cell type:code id: tags:
``` python
3 / 4
```
%%%% Output: execute_result
0.75
%% Cell type:markdown id: tags:
- Run the script from ipython.
%% Cell type:code id: tags:
``` python
run ../pyfiles/helloworld.py
```
%%%% Output: stream
Hello world
My name is Pierre
%% Cell type:code id: tags:
``` python
# name is defined in ../pyfiles/helloworld.py
print(name)
```
%%%% Output: stream
Pierre
%% Cell type:markdown id: tags:
- Help on an object can be displayed with the question mark (try it):
```ipython
name?
```
- Try to type "name." and to press on tab... The tab key is used to tell you how what you typed can be completed.
- Try to use the top and bottom arrows...
%% Cell type:markdown id: tags:
### Python in an IDE ([Spyder](https://pythonhosted.org/spyder/))
Launch the application Spyder, a Python IDE (Integrated development environment).
- a quite good code editor with:
- syntax coloring,
- code analysis powered by pyflakes and pylint,
- introspection capabilities such as code completion.
- Ipython console
- variable inspector
- ...
Remarks:
- 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)).
- a good modern open-source editor: [Visual Studio Code] (https://code.visualstudio.com/docs/languages/python).
- 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), or [Visual Studio Code](https://code.visualstudio.com/docs/languages/python)).
%% Cell type:markdown id: tags:
### Python in the browser ([Jupyter](https://jupyter.readthedocs.io))
The presentations of this python training are made with Jupyter (demonstration).
This is a very powerful tool to present results (see these [examples](http://nbviewer.jupyter.org/)).
......
......@@ -12,8 +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",
"Pierre Augier (LEGI), Cyrille Bonamy (LEGI), Eric Maldonado (Irstea), Franck Thollard (ISTerre), Christophe Picard (LJK), Loïc Huder (ISTerre)\n",
" \n",
"\n",
"# Characteristics of the Python language"
......
%% Cell type:markdown id: tags:
# Python training UGA 2017
**A training to acquire strong basis in Python to use it efficiently**
Pierre Augier (LEGI), Cyrille Bonamy (LEGI), Eric Maldonado (Irstea), Franck Thollard (ISTerre), Christophe Picard (LJK),
Loïc Huder (ISTerre)
Pierre Augier (LEGI), Cyrille Bonamy (LEGI), Eric Maldonado (Irstea), Franck Thollard (ISTerre), Christophe Picard (LJK), Loïc Huder (ISTerre)
# Characteristics of the Python language
%% Cell type:markdown id: tags:
## Characteristics of the Python language
- Open-source language, interpreters and ecosystem
- Interpreted (but there are tools to compile Python code)
- Automatic memory management
- Dynamically strongly typed (see next slides)
- Gradual learning curve
- A philosophy: the [Zen of Python](https://www.python.org/dev/peps/pep-0020/)
- Very clean and readable
- Indentation defines the blocks
- Style coding is important: [pep8](https://www.python.org/dev/peps/pep-0008/) (see next slides)
- Only few [keywords](https://hg.python.org/cpython/file/3.6/Lib/keyword.py) and [built-in functions](https://docs.python.org/3/library/functions.html) (see next slides)
- Errors should never pass silently
- Multi-paradigm (sequential, object-oriented, functional)
- "Batteries Included": [the standard library](https://docs.python.org/3/tutorial/stdlib.html)
%% Cell type:markdown id: tags:
## PEP8 (Python Extension Proposal)
https://www.python.org/dev/peps/pep-0008/
- Code layout
- Imports
- Whitespace in expressions and statements
- Comments
- Documentation strings
- Naming conventions
- Programming recommendations
%% Cell type:markdown id: tags:
## PEP8: examples of bad and good style practices
%% Cell type:code id: tags:
``` python
# bad (spaces between operator)
number=0
# ok
number = 0
```
%% Cell type:code id: tags:
``` python
# bad (indentation with 2 spaces, has to be 4)
if number == 0:
number = 1
# ok
if number == 0:
number = 1
```
%% Cell type:code id: tags:
``` python
# bad (space after ,)
mylist = [1,2,3]
# ok
mylist = [1, 2, 3]
```
%% Cell type:markdown id: tags:
## Keywords
%% Cell type:code id: tags:
``` python
help("keywords")
```
%%%% Output: stream
Here is a list of the Python keywords. Enter any keyword to get more help.
False def if raise
None del import return
True elif in try
and else is while
as except lambda with
assert finally nonlocal yield
break for not
class from or
continue global pass
%% Cell type:markdown id: tags:
plus 68 [built-in functions](https://docs.python.org/3/library/functions.html)... plus few [built-in constants](https://docs.python.org/3/library/constants.html)... plus [built-in exceptions](https://docs.python.org/3/library/exceptions.html)!
%% Cell type:markdown id: tags:
## Dynamically and strongly typed: objects and variables
The function `type` returns the type of an **object**:
%% Cell type:code id: tags:
``` python
type('hello')
```
%%%% Output: execute_result
str
%% Cell type:code id: tags:
``` python
type(2)
```
%%%% Output: execute_result
int
%% Cell type:code id: tags:
``` python
type(2.)
```
%%%% Output: execute_result
float
%% Cell type:code id: tags:
``` python
type(2 + 2)
```
%%%% Output: execute_result
int
%% Cell type:code id: tags:
``` python
type(2 + 2.)
```
%%%% Output: execute_result
float
%% Cell type:code id: tags:
``` python
type(True)
```
%%%% Output: execute_result
bool
%% Cell type:markdown id: tags:
## Dynamically and strongly typed: objects and variables
**Variables** are just tags pointing towards objects. New variables can be used when needed. They are not associated with a type but only with an object (which has a type)...
%% Cell type:code id: tags:
``` python
myvar = 1
print(myvar, type(myvar))
```
%%%% Output: stream
1 <class 'int'>
%% Cell type:code id: tags:
``` python
myvar = 'hello'
print(myvar, type(myvar))
```
%%%% Output: stream
hello <class 'str'>
%% Cell type:markdown id: tags:
## Spaces for objects and variables (names)
Objects and variables (names) are two very different concepts:
- Objects live in one "object space". They have an address in the memory.
- Names live in namespaces.
It is often interesting to represent the execution of a Python program in an **"object space - namespaces" diagram**.
The Zen of Python says "Namespaces are one honking great idea -- let's do more of those!". A namespace is created for every module (file) and for every function execution,
%% Cell type:markdown id: tags:
## You have to use a good editor!!
Python:
- (most of the time) interpreted (no compilation)
- very dynamic
- pep8 (style).
- indentation defines the blocks
The editor can and has to help you!!
- syntax coloring
- automatic indentation
- code analysis (code analysis powered by pyflakes and pylint)
- introspection capabilities such as code completion
%% Cell type:markdown id: tags:
## Do it yourself: PEP8 checker with Spyder editor
In Spyder, open the file `./pyfiles/wrong.py` and see what append.
Activate the "Real time code style analysis (PEP 8)" (Preferences -> Editor -> Code Introspection/Analysis).
Correct the file to remove the warnings.
......
{%- extends 'basic.tpl' -%}
{% from 'mathjax.tpl' import mathjax %}
// added by Pierre Augier
{%- block input_group scoped -%}
{%- if not cell.metadata.get('source_hidden', False) -%}
{{ super() }}
{%- endif -%}
{%- endblock input_group -%}
{%- block output_prompt -%}
{%- if not cell.metadata.get('source_hidden', False) -%}
{{ super() }}
{%- endif -%}
{%- endblock output_prompt -%}
{%- block any_cell scoped -%}
{%- if cell.metadata.get('slide_start', False) -%}
<section>
......@@ -189,7 +202,12 @@ require(
controls: true,
progress: true,
history: true,
width: 1200,
// changed by Pierre Augier
width: '85%',
height: '100%',
slideNumber: true,
theme: Reveal.getQueryHash().theme, // available themes are in /css/theme
transition: Reveal.getQueryHash().transition || 'linear', // default/cube/page/concave/zoom/linear/none
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment