Python Forum
'str' object is not callable
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
'str' object is not callable
#1
this is my script below :
when i first run, everything is normal and prompt user "Do you want a new reading :"
but when i key in yes and the error 'str' object is not callable came out on this line "hex_number = str(hex(randomnumber))"
any idea how to solve this issue? i've check and confirm i dont have another str define else where ..

def main():    

    import random
    global hex
    

    randomnumber = random.randint(0,99)

    hex_number = str(hex(randomnumber))
    hex_numberd0 = '0x' + hex_number[2:]
    print('A random D0:', hex_number)

    randomnumber = random.randint(0,99)
    hex_number = str(hex(randomnumber))
    hex_numberd1 = '0x' + hex_number[2:]
    print('A random D1:', hex_number)

    randomnumber = random.randint(0,99)
    hex_number = str(hex(randomnumber))
    hex_numberd2 = '0x' + hex_number[2:]
    print('A random D2:', hex_number)

    D0 = hex_numberd0
    D1 = hex_numberd1
    D2 = hex_numberd2

    #hex coversion
    hex= D0
    dec0 = int(hex,16)
    print('Value in hexadecimal D0 :', hex)
    print('Value in decimal D0 :', dec0)

    hex= D1
    dec1 = int(hex,16)
    print('Value in hexadecimal D1 :', hex)
    print('Value in decimal D1 :', dec0)

    hex= D2
    dec2 = int(hex,16)
    print('Value in hexadecimal D2 :', hex)
    print('Value in decimal D2 :', dec0)

    #coversion ends
    
    #inclination calculation

    if(dec2 >> 7 == 1):
           signbit = -1
    else:
            signbit = 1

    Data0 = (dec0 >> 6)
    Data1 = (dec1 <<2)
    Data2 = ((dec2&127)<<10)

    print("D0 =", Data0)
    print("D1 =", Data1)
    print("D2 =", Data2)

    DataI = signbit*(Data0 + Data1 + Data2)/1000
    print("inclination = ", DataI)

    restart = input("Do you want a new reading :   ").lower()
    if restart == "yes":
        main()

    else:
        exit()
main()
Yoriz write Jul-28-2021, 09:39 AM:
Please post all code, output and errors (in their entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Reply


Messages In This Thread
'str' object is not callable - by ZYSIA - Jul-28-2021, 09:27 AM
RE: 'str' object is not callable - by Yoriz - Jul-28-2021, 09:46 AM
RE: 'str' object is not callable - by ZYSIA - Aug-03-2021, 03:40 AM
RE: 'str' object is not callable - by ndc85430 - Aug-03-2021, 04:41 AM
RE: 'str' object is not callable - by ZYSIA - Aug-03-2021, 05:23 AM
RE: 'str' object is not callable - by ndc85430 - Aug-03-2021, 05:58 AM
RE: 'str' object is not callable - by ZYSIA - Aug-03-2021, 06:11 AM
RE: 'str' object is not callable - by ndc85430 - Aug-03-2021, 06:45 AM
RE: 'str' object is not callable - by deanhystad - Aug-03-2021, 03:26 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  error in class: TypeError: 'str' object is not callable akbarza 2 525 Dec-30-2023, 04:35 PM
Last Post: deanhystad
  TypeError: 'NoneType' object is not callable akbarza 4 1,022 Aug-24-2023, 05:14 PM
Last Post: snippsat
  [NEW CODER] TypeError: Object is not callable iwantyoursec 5 1,392 Aug-23-2023, 06:21 PM
Last Post: deanhystad
  Need help with 'str' object is not callable error. Fare 4 861 Jul-23-2023, 02:25 PM
Last Post: Fare
  TypeError: 'float' object is not callable #1 isdito2001 1 1,092 Jan-21-2023, 12:43 AM
Last Post: Yoriz
  'SSHClient' object is not callable 3lnyn0 1 1,178 Dec-15-2022, 03:40 AM
Last Post: deanhystad
  TypeError: 'float' object is not callable TimofeyKolpakov 3 1,476 Dec-04-2022, 04:58 PM
Last Post: TimofeyKolpakov
  API Post issue "TypeError: 'str' object is not callable" makeeley 2 1,936 Oct-30-2022, 12:53 PM
Last Post: makeeley
  Merge htm files with shutil library (TypeError: 'module' object is not callable) Melcu54 5 1,607 Aug-28-2022, 07:11 AM
Last Post: Melcu54
  [split] TypeError: 'int' object is not callable flash77 4 2,775 Mar-21-2022, 09:44 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

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