Cantor – dynamic keywords in python backend

In previous post, I mentioned about dynamic keywords in python backend. The idea is, after import a python module in Cantor workspace, functions, keywords, variables, and more from this module are load by Cantor and available to syntax highlighting and tab complete.

This feature is implemented for now. You can test it compiling Cantor from python-backend branch.

But, let me show more information about this feature.

There are several ways to import a python module in python console. You have “import modulename”, “import modulename as modulevariable”, “from modulename import *”, “from modulename import function_1, function_2, …”, and more. Each import way causes different consequences to user experience.

The four import ways mentioned in previous paragraph are supported by python backend. I will show these different import ways and how python backend behave for each one.

import modulename

The more basic import way. After this command, a variable named “modulename” is defined and the functions and more keywords of this module are available to access using “modulename.keyword”.

python_import_modulenameTab Complete


Syntax Highlighting

import modulename as modulevariable

This way the user define a name “modulevariable” to reference “modulename”, and “modulename” is not defined. So, you can access the functions and more from “modulename” using “modulevariable.keyword”.


Tab Complete


Syntax Highlighting

from modulename import *

This way the user import all functions and keywords from “modulename” but anything variable is defined to access “modulename”. The functions of the module are accessed directly.


Tab Complete


Syntax Highlighting

from modulename import function_1, function_2, …

The user import only specific functions from a “modulename”, no all functions.


Tab Complete


Syntax Highlighting

Cantor plugin

I developed a Cantor plugin to import modules. This plugin open a dialog to user enter a modulename and, after press Ok, Cantor run “import modulename” and keywords are available. The diaglog is accessible by “Packaging” menu, in toolbar.


Cantor Plugin

Handling Errors

The backend can identify several errors during import.


Handling Errors


Well, the feature is working and it is mature for use, however it don’t support all import ways in python. But, I think these five ways cover the most commons import ways used by most python scientific users.

The important thing is, this feature enable python backend to support the several python modules, and no only scipy, numpy, and matplotlib, as I proposed in begin of this project.

Let me know how you import a module in python. I will develop support to more import ways in future versions of the backend.

For now, wait for more news of this project soon!

9 comentários em “Cantor – dynamic keywords in python backend”

    1. Yes, after the python backend code merged in Cantor master branch, we will update this page.

      Really, several backends are missing in this page (Octave, Qualculate, Scilab, and now, Python).

  1. Another import that is important to consider is the __from_future__, particularly “division” and “print_statement”. Although these could be specified in a configuration dialog rather than having to manually run them each time, it would still be good to support running them manually.

    Will it be possible to configure the python backend to automatically import particular modules when you first start it up? Either specifying modules in a configuration dialog, or better yet allowing you to specify arbitrary lines that are executed each time the backend is started (or both).

  2. Pingback: Links 16/8/2013: Tropico 5 for GNU/Linux, KDE 4.11 Released | Techrights

Deixe um comentário

O seu endereço de e-mail não será publicado.