5

I'm in the process of setting up a Matlab like environment so I downloaded the latest version of python(x,y) with all the modules that come with it and downloaded python 3.4.1. Does python(x,y) not run the latest version of python? I noticed because the python(x,y) shell doesn't auto calculate mathematical operations into floats which I read is a difference between python 2.x and 3.x. Do I just have to wait for a new release of (x,y) or am I missing something here?

matsjoyce
  • 5,744
  • 6
  • 31
  • 38
Fanylion
  • 364
  • 2
  • 5
  • 14
  • Are you on Windows? You could use winpython which has a 64-bit 3.3.5.0 release: http://sourceforge.net/projects/winpython/files/WinPython_3.3/3.3.5.0/ – EdChum Jul 31 '14 at 07:43
  • Python does not auto calculate into floats. But you can easily do that by `8/3 will be 2` but `8.0/3 or 8/3.0 will be 2.6666666666666665`. – Tanmaya Meher Jul 31 '14 at 07:47
  • 1
    @TanmayaMeher That is mostly true for Python 2. Python 3 does division properly. And you can make Python 2 do that as well. See my answer below. – Roland Smith Jul 31 '14 at 08:15
  • yep ! I forgot ! `8/3 gives 2.666...` in python 3 and `8//3 gives 2`. Thanks for reminding. I need a lot of code practice in python 3 now probably. :) May be reproducing the same codes with python 3 will help that i did with python 2. – Tanmaya Meher Jul 31 '14 at 08:20
  • Thanks. I think I will give winpython a try since it seems to be similar to python(x,y) but in 3.x. – Fanylion Jul 31 '14 at 19:38
  • 2
    Given that the whole discussion went on the division issue, I'd like to give you a bit more context about PythonXY. The latest available Python version is `3.4.1`, as you discovered, but PythonXY doesn't support it, just the previous one, which is Python `2.7`. – Carlos Cordoba Aug 01 '14 at 04:01
  • Thanks for the comment. Matlab is the first language I learned so the idea of not having a GUI, scripting, calculating environment all in one exe from one website was foreign to me. With a full license provided to me by my university I never had a reason to learn anything else. I decided Matlab was too esoteric a language to only know so I branched out. Slow going, but getting there. – Fanylion Aug 02 '14 at 07:22

3 Answers3

1

You can make Python 2 behave the same as Python 3 w.r.t. division with the following command;

from __future__ import division

Imports from __future__ should be the in the top of the file. There is probably a way to auto-load this expression (I know it is possible in IPython) but I'm not familiar with python(x,y).

Roland Smith
  • 42,427
  • 3
  • 64
  • 94
  • 1
    If you're running Python 2, this is an absolutely terrible idea; it breaks the reasonable expectations of people who read your code. – sapi Jul 31 '14 at 08:46
  • 3
    @sapi This is at the very head of a file, which people should notice even when skimming. And there is literally no point in the old behavior in 99% of cases... – Tobias Kienzler Dec 09 '14 at 09:21
  • 2
    This is actually the only way to run a script both compatible with Python 2.7 and 3.4 and is, with unicode_literals, print_functions and absolute_import, a standard line for every new Python 2.7 code. – Bite code Dec 17 '14 at 12:46
1

For learning more about Python do the tutorials available via python.org. The latest version of Python3 is recommend.

Since you are in a transition process, take a look at SciPy (http://www.scipy.org) and Sage (http://www.sagemath.org/tour.html). These might be a better fit for the problems you need to solve.

If you do a lot of interactive work at the terminal, take a look at ipython (http://ipython.org).

Regarding the division operator is defaults to integer division in Python2, but will be just normal division in Python3. You can change this by using the -Q flag when starting the interpreter. (Do: python --help) For example:

$ python2.7 -Qnew
Python 2.7.6 (default, Nov 18 2013, 15:12:51) 
[GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.2.79)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> 1/2
0.5
>>> 
$ python2.7
Python 2.7.6 (default, Nov 18 2013, 15:12:51) 
[GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.2.79)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> 1/2
0
>>> 
$ python3.4
Python 3.4.1 (default, May 21 2014, 01:39:38) 
[GCC 4.2.1 Compatible Apple LLVM 5.1 (clang-503.0.40)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> 1/2
0.5
>>> 
FredrikHedman
  • 1,223
  • 7
  • 14
0

Having the feeling that the original question is epsecially regarding the python(x,y)-distribution and Python 3 my (long) answer to this is:

I used this distribution for many years and like it. But for me it seems that there are no plans to upgrade it to include a python 3 environment.

These days I would recommend the Anaconda distribution/project (https://www.anaconda.com/). Very similar to the python(x,y)-idea but better maintained and supporting the "latest of everything".

Thomas
  • 1
  • 1