__init__ : constructeur, est appelé lors de la création de l'objet
__del__ : pour détruire un objet ( del mon_objet )
__repr__: définir la façon d'afficher l'objet quand on l'appel tel quel (remplace le <__main__.XXX object at 0x00B46A70>)
__str__ : définit ce que affiche en faisant un print de l'objet (print mon_objet)
__getattr__: définit ce qu'il se passe si on appet un attribut qui n'existe pas
il faut mettre un paramètre : def __getattre__(self, nom):
si on appel mon_objet.attribut_existe_pas
ça lance cette méthode
__setattr__ : définit ce qu'il se passe quand on attribue quelque chose à un objet
__delattr__ : pour supprimer un attribut (del mon_objet.attibut)
__getitem__: mon_objet[index]
__setitem__: mon_objet[index] = valeur
__delitem__ : del mon_objet[index]
__len__: len(objet)
__add__: mon_objet + 5
__sub__ : mon_objet - 5
__mul__ : mon_objet * 5
__truediv__ : mon_objet / 5
__floordiv__ : mon_objet // 5
__mod__ : mon_objet % 5
__pow__ : mon_objet ** 5
https://openclassrooms.com/courses/apprenez-a-programmer-en-python/les-methodes-speciales-1
lundi 18 avril 2016
samedi 19 mars 2016
[Arduino] - Envoyer du code vers l'arduino en ligne de commande
il faut avoir installé le logiciel arduino
les dossiers lib et src sont créés
lib sert a mettre les librairies qui peuvent etre utiles
dans src il faut mettre le code sous forme de fichier .ino (ici le fichier blink.ino s'est créé automatiquement)
Pour compiler, il faut etre dans le dossier test-blink
sudo apt-get install arduinoPour envoyer du code sans passer par le logiciel arduino (https://github.com/pobot/ino)
sudo pip install inoil faut créer un dossier et lancer une commande pour créer l'arborescence type
mkdir test-blink-t blink: utilise le template blink
cd test-blink
ino init -t blink
les dossiers lib et src sont créés
lib sert a mettre les librairies qui peuvent etre utiles
dans src il faut mettre le code sous forme de fichier .ino (ici le fichier blink.ino s'est créé automatiquement)
Pour compiler, il faut etre dans le dossier test-blink
ino buildune fois le code compiler, pour uploader vers l'arduino voici la commande
ino uploadpour pouvoir lirele port série directement dans la console il faut installer picocom
sudo apt-get install picocompour afficher les données du port serie, pour sortir il faut faire Ctrl+A puis Ctrl+X
ino serialsource : http://inotool.org/quickstart
dimanche 13 mars 2016
[LINUX] - lancer un script au démarrage
lancer un script au démarrage
ajouter la ligne de commande dans /etc/rc.local
ne pas oublier de donner les droits d'exucution au script
ajouter la ligne de commande dans /etc/rc.local
ne pas oublier de donner les droits d'exucution au script
sudo chmod +x script.py
[RASPI] - SDL sur raspberry pi
Pour lancer directement un truc avec pygame il faut installer SDL apparemment
voici comment faire:
(source : https://solarianprogrammer.com/2015/01/22/raspberry-pi-raspbian-getting-started-sdl-2/)
Let’s start by updating our Raspbian installation, feel free to skip this step if your system was recently updated:
Assuming, you’ve had no error in the configure phase, you can actually build and install the library:
voici comment faire:
(source : https://solarianprogrammer.com/2015/01/22/raspberry-pi-raspbian-getting-started-sdl-2/)
Let’s start by updating our Raspbian installation, feel free to skip this step if your system was recently updated:
sudo apt-get updateNext, we will need to install some libraries that will be used when we build SDL 2:
sudo apt-get upgrade
sudo apt-get install build-essential libfreeimage-dev libopenal-dev libpango1.0-dev libsndfile-dev libudev-dev libasound2-dev libjpeg8-dev libtiff5-dev libwebp-dev automakeSDL 2 can be downloaded from https://www.libsdl.org/download-2.0.php, be sure to select the source code archive, SDL2-2.0.3.tar.gz, or a newer version if available. You can download and extract the archive directly on your Raspberry Pi:
cd ~Now, it is time to configure SDL 2:
wget https://www.libsdl.org/release/SDL2-2.0.3.tar.gz
tar zxvf SDL2-2.0.3.tar.gz
cd SDL2-2.0.3 && mkdir build && cd build
../configure --disable-pulseaudio --disable-esd --disable-video-mir --disable-video-wayland --disable-video-x11 --disable-video-openglor, if you have a Raspberry Pi 2 or 3:
../configure --host=armv7l-raspberry-linux-gnueabihf --disable-pulseaudio --disable-esd --disable-video-mir --disable-video-wayland --disable-video-x11 --disable-video-openglThe above options will make sure, SDL 2 is built with the OpenGL ES backend and that any SDLapplication will run as a full screen application, the windowed mode under X tends to be more buggy onRaspberry Pi. On the plus side, you will be able to launch your application, or game, directly from the text interface without the overhead of running the X server. If you wish you can start your application fromLXDE (the default window manager for Raspbian) and the application will run full screen.
Assuming, you’ve had no error in the configure phase, you can actually build and install the library:
make -j 4
sudo make install
Inscription à :
Articles (Atom)