Ex-Mente / auxi.0

GNU Lesser General Public License v3.0
8 stars 8 forks source link

Bridging the gap of integer division between python 2 and python 3 #136

Open SShilo opened 8 years ago

SShilo commented 8 years ago

System Details

auxi version: 0.3.1 Python version: 3.5.2 OS details: Win 10, 32-bit

Background

NB: If you are using python 3 safely ignore all of this.

Doing a calculation such as 2/5 and 3/2 on a typical calculator should yield 0.4 and 1.5 respectively, as python 3 does, however, in python 2 these calculations will return 0 and 1 respectively. This is because python somehow seems to ignore the float component of the number (i.e. ignoring everything after the decimal point). This is a very well known problem.

Purpose

Correcting the fault of integer division in python 2 IDES when running code.

Approach

Import the division module from the future magic module i.e. (from future import division) at the top of each .py file. This is shown in the template below.

!/usr/bin/env python3

""" <> This module ... """

from future import division

import <>

import <>

import <>

version = '0.3.1' license = 'LGPL v3' copyright = 'Copyright 2015-2016, Ex Mente Technologies (Pty) Ltd' author = '<>' credits = [<>] maintainer = 'Christoff Kok' email = 'christoff.kok@ex-mente.co.za' status = 'Planning'

<>

if name == "main": import unittest from <<Add the relevant test module(s) here.>> import * unittest.main()