QGIS-Using the python console

As previously said, the QGIS python console is a good way to test step by step your code before implementing it to your plugin…

To access the python console, just go to plugins > python console.


Notice the example instruction in the shell iface.zoomFull(): this command is applied on the interface object called iface. It performs a zoom that makes all your objects visible.
Just try typing it in the shell to see the result:

The QGIS console is similar to a python shell but there are some limitations like the impossibility of writing multiples lines of code in one time,as it is possible with the usual python shell.

Usually, the “for” and “while” statements require multiples lines. They are often used to get lists. As the “for” and “while” statements are unavalaible, you’ll have to deal with the notion of list comprehension to get a list of values.
Look at these links to learn how to use them:
http://docs.python.org/tutorial/datastructures.html
http://www.secnetix.de/olli/Python/list_comprehensions.hawk
In the examples i’ll show you in the next posts, you’ll see some examples of these notions.

You can also have to use map, filter, and reduce functions, that are used on lists:
http://docs.python.org/library/functions.html

To write functions, you’ll have to get familiar with lambda function…
http://www.secnetix.de/olli/Python/lambda_functions.hawk


OpenEdition vous propose de citer ce billet de la manière suivante :
mathieu rajerison (1 avril 2009). QGIS-Using the python console. Datagistips. Consulté le 11 juillet 2025 à l’adresse https://doi.org/10.58079/nh09


Une réflexion sur « QGIS-Using the python console »

  1. I would like to see more how to use the python console. Any example python script that do geo processing joining table with shapefile table. Noli

Laisser un commentaire

Votre adresse e-mail ne sera pas publiée. Les champs obligatoires sont indiqués avec *

This site uses Akismet to reduce spam. Learn how your comment data is processed.