Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AttributeError: 'module' object has no attribute 'div'

Tags:

python-3.x

I tried to run following program of using python 3.2 , there is error: 'module' object has no attribute 'div' Can anybody tell me what should I do to fix this? i really appreciate it !

import operator 
ops = {'+':operator.add,'-':operator.sub,'*':operator.mul,'/':operator.div}

AttributeError: 'module' object has no attribute 'div

like image 235
user3034622 Avatar asked Dec 10 '13 03:12

user3034622


1 Answers

According to the docs, there is a truediv and a floordiv in Python 3. You need to use one of these.

operator.truediv(a, b) operator.__truediv__(a, b) Return a / b where 2/3 is .66 rather than 0. This is also known as “true” division.

operator.floordiv(a, b) operator.__floordiv__(a, b) Return a // b

like image 65
perreal Avatar answered Oct 27 '22 04:10

perreal