Python Forum
Type float doesn't have expected attribute '__div__'
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Type float doesn't have expected attribute '__div__'
#1
I'm playing with some formulas and I ran across this warning
 Type float doesn't have expected attribute '__div__' with the  "resist_2" in this line:

volt_div(volt_in, resist_1, resist_2)
Here is the full function:
def volt_div(v_in, res_1, res_2):
    # resistor_2 = res_2    # Needed to make Python's __div__ happy
    v_out = v_in * (res_2 / (res_1 + res_2))

    print("Output of voltage divider = {:.4f} VDC".format(v_out))
    return

volt_in = 10.0
resist_1 = 10.0
resist_2 = 10.0

volt_div(volt_in, resist_1, resist_2)
It doesn't seem to affect the outcome, but I am curious as to what it means.
If it ain't broke, I just haven't gotten to it yet.
OS: Windows 10, openSuse 42.3, freeBSD 11, Raspian "Stretch"
Python 3.6.5, IDE: PyCharm 2018 Community Edition
Reply
#2
Is that coming from Pycharm? I just tried it on OS X, Python 3.5.2 and Python 2.7.12 without seeing that message.
Reply
#3
Yes, sorry, it's a warning in Pycharm.  The only info it gives is it's related to "dynamic dispatch and duck typing...".  What I find confusing  is if I rename (declare?) the variable within the function (renaming "res_2" to "resistor_2)" the warning goes away.  That, however seems a rather clunky way of fixing a problem,
If it ain't broke, I just haven't gotten to it yet.
OS: Windows 10, openSuse 42.3, freeBSD 11, Raspian "Stretch"
Python 3.6.5, IDE: PyCharm 2018 Community Edition
Reply
#4
python 3 uses __truediv__ instead of __div__ (and __floordiv__)

from docs:
Quote: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.
Reply
#5
So it's simply saying it's not backward compatible?  It's rather late and my brain is not as sharp as it should be (if it ever is) but why would it make a difference if the variable is defined within the function (which is apparently o.k.) as opposed to being passed to the function (which is not o.k.)
If it ain't broke, I just haven't gotten to it yet.
OS: Windows 10, openSuse 42.3, freeBSD 11, Raspian "Stretch"
Python 3.6.5, IDE: PyCharm 2018 Community Edition
Reply
#6
I'm fairly certain it's a Pycharm issue similar to https://intellij-support.jetbrains.com/h...arm-2017-1
Reply
#7
Thanks for going to the trouble of finding that post, I seriously doubt I would have found it.  I was certain it was a problem with how I had defined the function, it never crossed my mind it might be a problem with Pycharm.

Thanks again.
If it ain't broke, I just haven't gotten to it yet.
OS: Windows 10, openSuse 42.3, freeBSD 11, Raspian "Stretch"
Python 3.6.5, IDE: PyCharm 2018 Community Edition
Reply
#8
Quote:but why would it make a difference if the variable is defined within the function
It shouldn't, micsydel has to be right

There are other things in PyCharm that I haven't liked lately,
auto indent doesn't work properly with cut and paste for one and it's quite annoying.
Reply
#9
The function is quite simple in order to cause this.
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  python calculate float plus float is incorrect? sirocawa 6 357 Apr-16-2024, 01:45 PM
Last Post: DeaD_EyE
  Write Null values as 0.0 (float) type in csv mg24 3 1,394 Dec-07-2022, 09:04 PM
Last Post: deanhystad
  TypeError: sequence item 0: expected str instance, float found Error Query eddywinch82 1 5,163 Sep-04-2021, 09:16 PM
Last Post: eddywinch82
  Python generics: How to infer generic type from class attribute? Thoufak 0 2,843 Apr-25-2021, 09:31 AM
Last Post: Thoufak
  Error : "can't multiply sequence by non-int of type 'float' " Ala 3 3,105 Apr-13-2021, 10:33 AM
Last Post: deanhystad
  calculate_bai -- TypeError: unsupported operand type(s) for *: 'float' and 'NoneType' pantherd 1 3,279 Apr-21-2020, 12:31 PM
Last Post: anbu23
  TypeError: can't multiply sequence by non-int of type 'float' DimosG 3 3,396 Apr-04-2020, 05:16 AM
Last Post: michael1789
  AttributeError: type object 'FunctionNode' has no attribute '_TestValidateFuncLabel__ binhduonggttn 0 2,258 Feb-19-2020, 11:29 AM
Last Post: binhduonggttn
  TypeError: type str doesn't define __round__ method emmapaw24 7 29,847 Feb-03-2020, 08:38 PM
Last Post: snippsat
  Type hinting - return type based on parameter micseydel 2 2,519 Jan-14-2020, 01:20 AM
Last Post: micseydel

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020