Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #108937
| Path | csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail |
|---|---|
| From | Peter Otten <__peter__@web.de> |
| Newsgroups | comp.lang.python |
| Subject | Re: what is new with int conversion in Python 3 |
| Date | Sun, 22 May 2016 10:32:48 +0200 |
| Organization | None |
| Lines | 70 |
| Message-ID | <mailman.92.1463905981.27390.python-list@python.org> (permalink) |
| References | <648b46dc-c962-4f95-83bc-faa65ae3c51a@googlegroups.com> <nhrqri$inu$1@ger.gmane.org> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset="ISO-8859-1" |
| Content-Transfer-Encoding | 7Bit |
| X-Trace | news.uni-berlin.de hWZ7+Xep6WsUFpmF+t4+MQvdgwKtS9ZdAaR6C4cRiyYA== |
| Return-Path | <python-python-list@m.gmane.org> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.000 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'subject:Python': 0.05; 'python3': 0.05; 'valueerror:': 0.07; '"in': 0.09; '[1]:': 0.09; '[2]:': 0.09; 'indicates': 0.09; 'invocation': 0.09; 'literal': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'valueerror': 0.09; 'python': 0.10; 'python.': 0.11; 'integer.': 0.16; 'last)': 0.16; 'received:80.91.229.3': 0.16; 'received:dip0.t-ipconnect.de': 0.16; 'received:io': 0.16; 'received:plane.gmane.org': 0.16; 'received:psf.io': 0.16; 'received:t-ipconnect.de': 0.16; 'wrote:': 0.16; 'integer': 0.18; 'specifies': 0.18; 'fix': 0.21; 'elements': 0.23; "python's": 0.23; 'sets': 0.23; 'import': 0.24; '(most': 0.24; 'script': 0.25; 'header:User-Agent:1': 0.26; 'command': 0.26; 'header:X -Complaints-To:1': 0.26; 'follows': 0.29; 'implicitly': 0.29; 'subject:what': 0.29; 'work.': 0.30; 'probably': 0.31; 'another': 0.32; 'run': 0.33; 'problem': 0.33; 'enhanced': 0.33; 'foo': 0.33; 'skip:/ 20': 0.33; 'traceback': 0.33; 'could': 0.35; 'something': 0.35; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'received:org': 0.37; 'system.': 0.39; 'to:addr:python.org': 0.40; 'where': 0.40; 'subject:with': 0.40; 'received:de': 0.40; 'details': 0.62; 'introduction': 0.63; 'more': 0.63; 'sum': 0.69; '--->': 0.84; 'succeed.': 0.91 |
| X-Injected-Via-Gmane | http://gmane.org/ |
| X-Gmane-NNTP-Posting-Host | p57bd8e0d.dip0.t-ipconnect.de |
| User-Agent | KNode/4.13.3 |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.22 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| X-Mailman-Original-Message-ID | <nhrqri$inu$1@ger.gmane.org> |
| X-Mailman-Original-References | <648b46dc-c962-4f95-83bc-faa65ae3c51a@googlegroups.com> |
| Xref | csiph.com comp.lang.python:108937 |
Show key headers only | View raw
Sayth Renshaw wrote:
Read carefully:
> Run from the command line as follows
>
> python vectorsum.py n
>
> where n is an integer that specifies the size of the vectors.
So to run the script with Python 3 you could do
$ python3 vectorsum.py 42
in the shell. This implicitly sets sys.argv[1] to "42" so that the
conversion
size = int(sys.argv[1])
can succeed. This conversion failed because as the traceback indicates
> 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'
>
sys.argv[1] is "-f" which is not a valid (base-10) integer. This value
probably got into ipython3 because you invoked it with something like
$ ipython3 console -f foo
Python 3.4.3 (default, Oct 14 2015, 20:28:29)
Type "copyright", "credits" or "license" for more information.
IPython 1.2.1 -- An enhanced Interactive Python.
? -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help -> Python's own help system.
object? -> Details about 'object', use 'object??' for extra details.
In [1]: import vectorsum
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-1-b0b6e1aba9f9> in <module>()
----> 1 import vectorsum
/home/petto/vectorsum.py 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'
In [2]: ! python3 vectorsum.py 42
The last 2 elements of the sum [65600, 70602]
PythonSum elapsed time in microseconds 106
The last 2 elements of the sum [65600 70602]
NumPySum elapsed time in microseconds 121
By the way, I had to fix another problem to make the "In [2]:" invocation
work. Let's see if you can do that yourself.
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
what is new with int conversion in Python 3 Sayth Renshaw <flebber.crue@gmail.com> - 2016-05-22 00:26 -0700 Re: what is new with int conversion in Python 3 Chris Angelico <rosuav@gmail.com> - 2016-05-22 17:51 +1000 Re: what is new with int conversion in Python 3 Steven D'Aprano <steve@pearwood.info> - 2016-05-22 17:55 +1000 Re: what is new with int conversion in Python 3 Peter Otten <__peter__@web.de> - 2016-05-22 10:32 +0200 Re: what is new with int conversion in Python 3 Sayth Renshaw <flebber.crue@gmail.com> - 2016-05-22 03:59 -0700
csiph-web