Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python 3.x on python(x,y)?

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?

like image 706
Fanylion Avatar asked Nov 01 '22 19:11

Fanylion


2 Answers

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).

like image 83
Roland Smith Avatar answered Nov 15 '22 05:11

Roland Smith


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
>>> 
like image 38
FredrikHedman Avatar answered Nov 15 '22 04:11

FredrikHedman