Come eseguire un programma Python su LXTerminal Raspberry Pi

Come eseguire un programma Python su LXTerminal Raspberry Pi

If you are new to using Python on the Raspberry Pi, this article may help you.
First of all, let’s create a simple Python program directly from RPi module, using LeafPad text editor provisioned out of the box with Raspbian operating system.
Therefore, let’s open LeafPad, past the following Python program code snippet:

import datetime

dt = datetime.datetime.now()

print str(dt)

and save the fine on Desktop with name DateTimeProgram.py

Now open Raspbian terminal LXTerminal and type the following command to reach the Desktop folder:

cd /home/pi/Desktop

Next, type the following command to run DateTimeProgram Python program and type Enter key:

python DateTimeProgram.py

The program should now be running and print the dae and time on the output console.

Se sei un neofita nell’utilizzo di Python sul modulo Raspberry Pi, questo è un articolo che potrebbe esserti d’aiuto.
Creaiamo innanzitutto un semplice programma Python direttamente dal modulo RPi utilizzando l’editor di testo LeafPad fornito direttamente con l’istallazione di Raspbian.
Dunque, apriamo LeafPad, incolliamo la seguente porzione di programma Python:

import datetime

dt = datetime.datetime.now()

print str(dt)

e salviamo il file sul Desktop con il nome DateTimeProgram.py

Una volta creato il file sul Desktop, apriamo il terminal di Raspbian LXTerminal ed inseriamo il seguente comando per posizionarci nella cartella contente il programma (Desktop):

cd /home/pi/Desktop

successivamente, digitare il seguente comando per eseguire il programma Python e premere Invio:

python DateTimeProgram.py

Il programma dovrebbe avviarsi e visualizzare sulla console di output la data e l’ora corrente.

2 commenti

comments user
emiliano

un altro modo è quello di aggiungere al file, nella prima linea, lo shabang
#!/usr/bin/python

dare i diritti di esecuzione al file con

chmod +x DateTimeProgram.py

ed infine eseguire direttamente il file, sempre dalla dir Desktop,

./DateTimeProgram.py

    comments user
    Nicola Celiento

    Grazie Emiliano per l’ottimo contributo!

Lascia un commento

Il tuo indirizzo email non sarà pubblicato. I campi obbligatori sono contrassegnati *