Python Forum
Python calling function unexpectedly
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python calling function unexpectedly
#2
When setting a variable or sequence index to a function, do not use parentheses. Parentheses signify that the function should be called. If you use the function name by itself, the variable or index is instantiated to the function itself.

if_tree(
    MAIN_TEXT, 
    ["1", "2"], 
    ["Q", "H", "R"], 
    [basic_option, advanced_option, quit_program, display_help, exec("restart_calculator()")]
)
Other than that, I believe this script should be refactored into a class called Calculator. The function input() returns a string so there is no need for str(input()).
Reply


Messages In This Thread
RE: Python calling function unexpectedly - by stullis - Jan-24-2019, 10:40 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  python script is hanging while calling a procedure in database prasanthi417 4 546 Jan-17-2024, 02:33 PM
Last Post: deanhystad
  calling external function with arguments Wimpy_Wellington 7 1,496 Jul-05-2023, 06:33 PM
Last Post: deanhystad
  Calling a function (which accesses a library) from another file mouse9095 4 839 Jun-07-2023, 08:55 PM
Last Post: deanhystad
  PyRun_SimpleFile calling multiprocessing Python Class cause endless init loop Xeno 2 1,065 Sep-19-2022, 02:32 AM
Last Post: Xeno
Sad Iterate randint() multiple times when calling a function Jake123 2 2,082 Feb-15-2022, 10:56 PM
Last Post: deanhystad
  Calling a class from a function jc4d 5 1,857 Dec-17-2021, 09:04 PM
Last Post: ndc85430
  [Solved] TypeError when calling function Laplace12 2 2,918 Jun-16-2021, 02:46 PM
Last Post: Laplace12
  Calling python from c++ in visual studio pdk5 0 2,182 May-24-2021, 10:18 AM
Last Post: pdk5
  Calling Oracle REST SQL from Python johnjacob 2 2,063 Nov-05-2020, 04:19 AM
Last Post: johnjacob
  calling a function and argument in an input phillup7 3 2,633 Oct-25-2020, 02:12 PM
Last Post: jefsummers

Forum Jump:

User Panel Messages

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