Python_royal

Le Python est un super langage car il est à la fois très simple à manipuler et très complet.

IPython est un interpréteur Python amélioré, c’est l’outil idéal pour débuter et/ou pour tester ce langage.

En plus de l’interpréteur standard, il permet un debug plus complet, la complétion des commandes (méthodes et attributs), l’introspection, …

Il permet aussi de tester des programmes graphiques en TKinter, Qt, GTK ou wxWidgets.

Bref il faut l’avoir chez soi, d’autant plus qu’il ne vous en coûtera que quelques Mo.

 

Pour IPython3 :

apt-get install ipython3

 

Quelques exemples :

Complétion (avec le module Math) :

import math
carre = 16
math.s<strong><TAB></strong>
<span style="color: #ff0000;">math.sin math.sinh math.sqrt</span>
math.sqrt(carre)
<span style="color: #ff0000;">4</span>

Introspection (A quoi sert cette méthode ?)

import os
os.popen<strong>?</strong>
<span style="color: #ff0000;">Type:function
String form: ...</span>

 

Introspection (Comment est codée cette méthode ?)

import os
os.popen<strong>??</strong>
<span style="color: #ff0000;">Type:function
...</span>
<span style="color: #ff0000;">def popen(cmd, mode="r", buffering=-1):</span>
<span style="color: #ff0000;">    if not isinstance(cmd, str):</span>
<span style="color: #ff0000;">...</span>

 

Hello world graphique avec TKinter :

Nécessite TK (apt-get install python3-tk)

import tkinter
fenetre = tkinter.Tk()
<span style="color: #ff0000;">(une fenètre s'ouvre)</span>
titre = tkinter.Label(fenetre,text='Hello world !')
titre.pack()
fenetre.mainloop()
<span style="color: #ff0000;">(la fenêtre affiche votre Hello world)</span>

 

That’s all folks !

 

 

Sur le même sujet :