[Linuxtrent] Re: And Logico in Python...

  • From: Lele Gaifax <lele@xxxxxxxxxxxxxxxxxxx>
  • To: linuxtrent@xxxxxxxxxxxxx
  • Date: Wed, 8 Jul 2009 11:23:55 +0200

On Wed, 8 Jul 2009 11:03:27 +0200
Alex <magobin@xxxxxxxxx> wrote:

> >Così su due piedi non saprei la differenza del comportamento tra
> >interprete e script. In ogni caso ti suggerisco di usare
> >int(raw_input()) invece di raw_input() in entrambi casi. In questo
> >modo i valori letti verranno interpretati come numeri interi ed i
> >confronti funzioneranno regolarmente.
> 
> SUUUUUBDOLOOOOOO....

Non direi...

> hai ragione...così funziona...possibile che il raw_input abbia un
> tipo di default ??...perchè nell'interprete funziona..solo che il
> valore lo assegno direttamente!!

Gran fatto!

>>> help(raw_input)
Help on built-in function raw_input in module __builtin__:

raw_input(...)
    raw_input([prompt]) -> string

    Read a string from standard input.  The trailing newline is stripped.
.........^^^^^^^^
    If the user hits EOF (Unix: Ctl-D, Windows: Ctl-Z+Return), raise EOFError.
    On Unix, GNU readline is used if enabled.  The prompt string, if given,
    is printed without a trailing newline before reading.

Forse intendevi usare input() invece, che fa quel che intendi:

>>> help(input)
Help on built-in function input in module __builtin__:

input(...)
    input([prompt]) -> value

    Equivalent to eval(raw_input(prompt)).

ma ha altre subdolezze/vantaggi, in quanto *valuta* l'input (quindi
puoi inserire una espressione, tipo 1+3*5)

ciao, lele.
-- 
nickname: Lele Gaifax    | Quando vivrò di quello che ho pensato ieri
real: Emanuele Gaifas    | comincerò ad aver paura di chi mi copia.
lele@xxxxxxxxxxxxxxxxxxx |                 -- Fortunato Depero, 1929.
--
Per iscriversi  (o disiscriversi), basta spedire un  messaggio con OGGETTO
"subscribe" (o "unsubscribe") a mailto:linuxtrent-request@xxxxxxxxxxxxx


Other related posts: