Python Forum
Calling functions by making part of their name with variable
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Calling functions by making part of their name with variable
#1
Hi,

I am new to python and programming in general.

I have the following 4 functions:
  • __scroll_down
  • __scroll_up
  • __scroll_left
  • __scroll_right

I also have a variable called direction which can contain either: down, up, left or right

Is there a way to call a function based on the variable name, maybe something like this __scroll_{direction}() ?

Thank you for your time and help
Crouz
Reply


Messages In This Thread
Calling functions by making part of their name with variable - by crouzilles - Nov-02-2023, 09:58 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Whys is asterisk and random variable necessary in these functions? rrowhe4d 5 1,553 Aug-05-2022, 07:53 AM
Last Post: Gribouillis
  How to write a part of powershell command as a variable? ilknurg 2 1,153 Jul-26-2022, 11:31 AM
Last Post: ilknurg
  Calling a base class variable from an inherited class CompleteNewb 3 1,742 Jan-20-2022, 04:50 AM
Last Post: CompleteNewb
  Calling functions from within a class: PYQT6 Anon_Brown 4 3,834 Dec-09-2021, 12:40 PM
Last Post: deanhystad
  How to include input as part of variable name Mark17 4 2,552 Oct-01-2021, 06:45 PM
Last Post: Mark17
Question Calling on a Variable using other Variables jacknewport 4 2,040 Jul-23-2021, 04:18 PM
Last Post: jacknewport
  How to use a variable in Python (2.x) to define decimal part? MDRI 4 2,369 May-07-2021, 12:39 AM
Last Post: MDRI
Question trouble with functions "def", calling/defining them Duck_Boom 13 4,450 Oct-21-2020, 03:50 AM
Last Post: Duck_Boom
  Print part of a variable rs74 4 2,628 Jul-27-2020, 04:39 PM
Last Post: rs74
  Function Recognises Variable Without Arguments Or Global Variable Calling. OJGeorge4 1 2,283 Apr-06-2020, 09:14 AM
Last Post: bowlofred

Forum Jump:

User Panel Messages

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