what is new with int conversion in Python 3

Chris Angelico rosuav at gmail.com
Sun May 22 03:51:51 EDT 2016


On Sun, May 22, 2016 at 5:26 PM, Sayth Renshaw <flebber.crue at gmail.com> wrote:
> However when I run this I get a valuerror. So either something has changed with int or datetime I cannot google a consistent answer.
>
>
> ---------------------------------------------------------------------------
> ValueError                                Traceback (most recent call last)
> <ipython-input-8-a54a878f293d> in <module>()
>      37    return c
>      38
> ---> 39 size = int(sys.argv[1])
>      40
>      41 start = datetime.now()
>
> ValueError: invalid literal for int() with base 10: '-f'
>
> Had this before?

Look carefully at the error, and the line that it's coming up on.
Firstly, you can rule out datetime, as nothing has been done with
datetime except import it. Secondly, the invalid literal doesn't look
like a decimal number at all; in fact, it looks to me like a flag of
some sort. Try adding this above the failing line:

print(sys.argv)

And also, try running this at the terminal:

$ file /usr/bin/env/python

How are you invoking Python? The shebang looks wrong; perhaps it
should be "/usr/bin/env python" (note the space where you have an
additional slash), but perhaps it's not even being significant here.

ChrisA



More information about the Python-list mailing list