Python Forum
Building a method name in a function
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Building a method name in a function
#1
Hi,
as an almost beginner, this is just a general knowledge question.
Let's say i have a class foo defining method1, method2, method3.
I'd like to have a function outside class foo, for example:
my_function(fooinstance,name,num),
and build the fooinstance method name by name+num, and then call fooinstance.(name+num).

I'd like to avoid bunch of tests of the kind:
if name==method and num==1: fooinstance.method1()

Is such behavior possible ? Otherwise, gotta code those 40 if..elif i want to avoid.

thanks
Reply


Messages In This Thread
Building a method name in a function - by ffgth - Oct-18-2020, 10:41 PM
RE: Building a method name in a function - by ffgth - Oct-18-2020, 10:55 PM
RE: Building a method name in a function - by buran - Oct-19-2020, 03:27 AM
RE: Building a method name in a function - by ffgth - Oct-19-2020, 11:35 AM
RE: Building a method name in a function - by buran - Oct-19-2020, 11:57 AM
RE: Building a method name in a function - by ffgth - Oct-19-2020, 01:01 PM
RE: Building a method name in a function - by buran - Oct-19-2020, 01:21 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Building a DoublyLinkedList in Python - - append method Drone4four 2 435 Jan-08-2024, 01:27 PM
Last Post: Drone4four
  i want to use type= as a function/method keyword argument Skaperen 9 1,902 Nov-06-2022, 04:28 AM
Last Post: Skaperen
  function/method help myv5285 3 2,822 May-17-2020, 04:19 AM
Last Post: buran
  Accessing method as function object ClassicalSoul 2 2,035 Feb-14-2020, 09:31 PM
Last Post: wavic
  got SyntaxError while building simple function zarize 2 2,134 Feb-14-2020, 10:51 AM
Last Post: zarize
  function vs method prateekshaw 2 2,198 Nov-14-2019, 07:00 PM
Last Post: DeaD_EyE
  I'm trying to figure out whether this is a method or function call 357mag 2 2,448 Jul-04-2019, 01:43 AM
Last Post: ichabod801
  function method problems drchar 2 2,926 Dec-11-2018, 02:38 PM
Last Post: buran
  Understanding Method/Function robdhunter 2 2,655 Mar-10-2018, 11:57 PM
Last Post: robdhunter
  How to pass value from method to function iFunKtion 11 8,830 May-23-2017, 05:06 PM
Last Post: iFunKtion

Forum Jump:

User Panel Messages

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