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
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With