<jupyter_start><jupyter_text>introduction to Python![python](img/python.png "Python logo")  Introduction- Computer language invented by <NAME> in 1989    - Guido is slowly retiring from the management of Python since summer 2018    - Massively used at Dropbox & Google (employers of Guido) - Open source    - BSD-like license (see [python license](https://docs.python.org/3/license.html))    - Means free for you    - Guaranteed to stay free - Easily extendable: The ideal `glue` language.    - in C, Fortran, …    - Once compiled, can be as fast as C - Portable    - Runs on any computer you may have access to - used by most of the synchrotron facilities  Why Python ?- [Python](https://www.python.org/) can be learned in a couple of days- It runs everywhere- Batteries are included- Ideal for prototyping- Can be extended into larger projects- Excellent community support- Interfaces to low-level languages (for performances)![batteries are included](img/batteries_included.png "Batteries included")  some mainstream libraries that might interest you - Graphical user interfaces & visualization:    - Bindings to Qt ([PyQt5](https://pypi.org/project/PyQt5/), [PySide2](https://pypi.org/project/PySide2/)), gtk ([PyGTK-PyGObject](https://pypi.org/project/PyGObject/)), Tcl/Tk ([tkinder](https://docs.python.org/3/library/tkinter.html)), [wxWidgets](https://www.wxwidgets.org/) - [wxGlade](http://wxglade.sourceforge.net/), …    - Libraries for visualization: [matplotlib](https://matplotlib.org/), [VTK](https://pypi.org/project/vtk/description), [bokeh](https://docs.bokeh.org/en/latest/), [bqplot](https://bqplot.readthedocs.io/en/latest/), …- scientific libraries    - [numpy](https://numpy.org/), [scipy](https://www.scipy.org/), various [scikit-image](https://scikit-image.org/), [-learn](https://scikit-learn.org/stable/), [-cuda](https://scikit-cuda.readthedocs.io/en/latest/) …    - [pandas](https://pandas.pydata.org/), [numba](https://numba.pydata.org/), [numexpr](https://github.com/pydata/numexpr), …- compression libraries    - [blosc](http://blosc.org/), [zlib](https://zlib.net/), [gzip](https://docs.python.org/3/library/gzip.html)...- imagning library    - [Pillow](https://pillow.readthedocs.io/en/stable/)    - [opencv](https://opencv-python-tutroals.readthedocs.io/en/latest/py_tutorials/py_tutorials.html)- [numfocus community](https://numfocus.org/)  some softwares / libraries using python in the synchrotrons world - [Savu](https://github.com/DiamondLightSource/Savu)- [astra](https://www.astra-toolbox.com/)- [crispy](http://www.esrf.eu/computing/scientific/crispy/)- [PyMca](http://pymca.sourceforge.net/)- [PyHST2](https://gitlab.esrf.fr/mirone/pyhst2)- [PyFAI](https://github.com/silx-kit/pyFAI)- [FabIO](https://github.com/silx-kit/fabio)- [silx](https://github.com/silx-kit/silx)- [bliss](https://gitlab.esrf.fr/bliss/bliss)- [PyNx](http://ftp.esrf.fr/pub/scisoft/PyNX/) Python documentation is all other the web:* [python official tutorials](https://docs.python.org/3/tutorial/index.html)* [esrf tutorials within python](https://github.com/silx-kit/silx-training/) (Introduction too python, silx, Object Oriented programming, HPC, software engineering)* [python-course](https://www.python-course.eu)* ...  warnings* [python2 is (almost) no more maintened](https://pythonclock.org/)* [python 3.5 will be drop soon](https://devguide.python.org/status-of-python-branches), most libraries are already dropping compatibility/maintenance for python 3.5  Now let's play with python & jupyter notebooks Jupyter-notebook / Jupyter-lab is a web interface for interactively programming in languages like JUlia, PYThon or R.Jupyter is a set of tools originally developed to make it easier for scientists to work with Python and data. It allows you to combine interactive Python exploration with prewritten programs and even text and equations for documentation. Jupyter isn’t a different programming language, it’s just a set of computer programs for working with the Python language. However, there are other ways to work with Python which will be introduced later in this course.  Notebook cellsWithin the notebook, each box is called “cell” and can be used for entering Python code or writing comments. For now I will ask you to clean up the content of all cells in this document by clicking:> > Cell (or edit in jupyter-lab) -> All Output -> Clear>  To run source code contqins in a cell, click the Run button (play icon) on the toolbar, or type Shift-Enter:<jupyter_code>print("Hello world")<jupyter_output><empty_output><jupyter_text>some simple calculation<jupyter_code>4+7/2<jupyter_output><empty_output><jupyter_text>Nota:  - the integer division is obtained from: // - The division has priority over addition<jupyter_code>4+7//2
2*3
3**2
9**0.5<jupyter_output><empty_output><jupyter_text>Getting help !Python has extensive **help** built in. You can execute `help()` for an overview or `help(x)` for any library, object or type x to get more information. For example: help(). Use `quit` to leave the help mode<jupyter_code>help()<jupyter_output><empty_output><jupyter_text>*note: the `help()` will wait until you specify the function for which you need help*<jupyter_code>help(print)<jupyter_output><empty_output><jupyter_text>Another option is to use the `?` after a function name like `print?`<jupyter_code>print?<jupyter_output><empty_output><jupyter_text>Variables & Values    A `name` that is used to denote something like a `value` is called a **variable**.In python, variables can be declared and values can be assigned to it using the **=** sign.<jupyter_code>x = 2          # anything after a '#' is a comment
y = 5
xy = 'Hey'
print(x+y, xy) # not really necessary as the last value in a bit of code is displayed by default in notebooks<jupyter_output><empty_output><jupyter_text>importing a library<jupyter_code>import sys
print(sys.version)
import os
print(os.path.exists('/'))<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13498066902000336, 'fraction_numerical': 0.006387628172802151, 'mean_word_length': 4.896927651139742, 'pattern_counts': {'":': 0, '<': 34, '<?xml version=': 0, '>': 39, 'https://': 36, 'lorem ipsum': 0, 'www.': 6, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '8', 'dir': 'jupyter-structured-clean-dedup', 'id': '582052', 'license': 'CC-BY-4.0', 'n_tokens_mistral': 1933, 'n_tokens_neox': 1864, 'n_words': 555, 'path': 'sesame/0_introduction.ipynb', 'repo_name': 't20100/silx-training', 'size': '5959'}