Skip to content

Comment on Pythonpy – Command-line Kung Fu with Python

Comments

Very nice.

However, division behavior was unexpected in Python 2. It looks like it imports division from __future__ without asking.

  python -V
  Python 2.7.8
  
  python -c 'print(4 / 3)'
  1
  
  In [1]: 4 / 3
  Out[1]: 1
  
  py '4 / 3'
  1.33333333333
EDIT: Yes, it does do that import, and others from __future__.

Unless these imports are essential to the operation of pythonpy, I suggest making these optional/configurable, and default to Python 2 defaults, i.e. don't import.

Since the tool is available for Python 2 and 3, it makes sense. It's a shell tool, not a programming tool. You want to have the same behavior as much as possible everywhere, and not have to think about which Python you are using right now. Any system other than windows will likely have several versions of Python installed.

Plus, it's easier to type // to get the old behavior than it would be to type from operator import truediv to get the new behavior otherwise.

OK, someone downvoted this. That's OK, but can you say why you think it's good for the default in Python 2 to not act like Python 2?

It wasn't me, but I can understand that for sharing scripts this should be quite useful. Also, I think the Python 3 division is way more logical (like most things in Python 3) and the old division is only one / more away. (// is integer division)

Also in a shared code base where you use division this is almost always necessary, or at least easier.

It's a generally accepted language wart, just like input() and raw_input().

/ for float division, // for integer division.

AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.