Cómo ejecutar Python en línea desde un shell bash


¿Hay un argumento Python para ejecutar código desde el shell sin iniciar un intérprete interactivo o leer desde un archivo? Algo similar a:

perl -e 'print "Hi"'
Author: Mike Müller, 2013-06-04

3 answers

Esto funciona:

python -c 'print "Hi"'
Hi
 65
Author: Mike Müller,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2013-06-04 01:07:14

Otra forma es usar la redirección de bash:

python <<< 'print "Hi"'

Y esto funciona también con perl, ruby, y lo que no.

 9
Author: michaelmeyer,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2013-06-05 10:58:14

Otra forma es utilizar el e módulo

Eg.

$ python -me 1 + 1
2
 1
Author: John La Rooy,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2013-06-04 01:24:33