Problems using struct pack/unpack in files, and reading them.

Chris Angelico rosuav at gmail.com
Sat Nov 14 21:23:59 EST 2015


On Sun, Nov 15, 2015 at 1:08 PM, Steven D'Aprano <steve at pearwood.info> wrote:
> number = +raw_input("enter a number: ")
>
> versus:
>
> text = raw_input("enter a number: ")
> try:
>     number = float(text)
> except ValueError:
>     number = int(text)

What kinds of strings can float() not handle but int() can, and in a
program that's going to group floats and ints together as "numbers",
will they ever be useful? I'd be more likely to write this as simply:

number = float(input("Enter a number: "))

(Also, I use Python 3. No raw. But same diff.)

ChrisA



More information about the Python-list mailing list