Python console/it: Difference between revisions

From FreeCAD Documentation
(Created page with "La console Python è un pannello che esegue un'istanza dell'interprete Python che può essere usata per controllare i processi di FreeCAD e...")
(Created page with "La console Python di FreeCAD ha l'evidenziazione di base della sintassi, in grado di differenziare con vari stili e colori, commenti, stringhe, valori numerici, funzioni integ...")
Line 6: Line 6:
La [[Python console/it|console Python]] è un pannello che esegue un'istanza dell'interprete [[Python/it|Python]] che può essere usata per controllare i processi di FreeCAD e creare e modificare gli oggetti e le loro proprietà.
La [[Python console/it|console Python]] è un pannello che esegue un'istanza dell'interprete [[Python/it|Python]] che può essere usata per controllare i processi di FreeCAD e creare e modificare gli oggetti e le loro proprietà.


La console Python di FreeCAD ha l'evidenziazione di base della sintassi, in grado di differenziare con vari stili e colori, commenti, stringhe, valori numerici, funzioni integrate, output di testo stampato e delimitatori come parentesi e virgole. Queste proprietà della console possono essere configurate nell'[[Preferenze_Editor/it|editor delle Preferenze]].
The Python console in FreeCAD has basic syntax highlighting, able to differentiate with various styles and colors, comments, strings, numeric values, built in functions, printed text output, and delimiters like parentheses and commas. These properties of the console can be configured in the [[Preferences_Editor|Preferences editor]].


[[File:FreeCAD_Python_console.png|800px]]
[[File:FreeCAD_Python_console.png|800px]]

Revision as of 22:32, 22 November 2019

(Gennaio 2020) FreeCAD è stato originariamente progettato per funzionare con Python 2. Poiché Python 2 ha raggiunto la fine del suo ciclo di vita nel 2020, lo sviluppo futuro di FreeCAD sarà realizzato esclusivamente con Python 3 e la compatibilità con le versioni precedenti non sarà supportata.

Introduzione

La console Python è un pannello che esegue un'istanza dell'interprete Python che può essere usata per controllare i processi di FreeCAD e creare e modificare gli oggetti e le loro proprietà.

La console Python di FreeCAD ha l'evidenziazione di base della sintassi, in grado di differenziare con vari stili e colori, commenti, stringhe, valori numerici, funzioni integrate, output di testo stampato e delimitatori come parentesi e virgole. Queste proprietà della console possono essere configurate nell'editor delle Preferenze.

The Python console showing messages when FreeCAD has just started.

Scripting

For absolute beginners, see: Introduction to Python, and Python scripting tutorial.

See also: FreeCAD scripting basics, and Scripted objects.

The Python console can perform basic code completion when a dot is written after an object; it will show public methods and attributes (variables) of the current object (class), for example, obj.

The console is also able to show the documentation string of a particular function when the opening parenthesis is written, for example, function(

Example Python code that produces objects in the 3D view.


The Python console automatically loads some modules, and defines some aliases.

App = FreeCAD
Gui = FreeCADGui

Therefore these are equal

App.newDocument()
FreeCAD.newDocument()

Actions

Right click on the Python console shows some commands:

  • Copy: stores the selected text in the clipboard for later pasting; it is disabled if nothing is selected.
  • Copy command: stores the selected command in the clipboard for later pasting; it is disabled if nothing is selected.
  • Copy history: copy the entire history of Python commands entered in this session.
  • Save history as: save the entire history of Python commands entered in this session to a text file.
  • Paste: paste previously copied text in the clipboard to the Python console.
  • Select all: selects all text in the Python console.
  • Clear console: erases all commands entered into the Python console. This is useful if the Python console is full of messages and previously entered commands that may be distracting when testing a new function. This is merely aesthetic, as this command doesn't delete existing variables nor clears the imported modules in the session.
  • Insert file name: opens a dialog to search for a file in the system, then it inserts the full path of the file. This is useful to test functions that process an input file, without having to write the entire name in the console, which is error prone. This command does not run the file, and does not import it as a Python module, it just returns the full path of that file.
  • Word wrap: wrap very long lines that exceed the horizontal dimension of the Python console.

Template:Interface/it