Python Forum
Call method from another method within a class
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Call method from another method within a class
#3
Thanks! Tried to tag the python code according to the instructions.

I modified your code slightly so that it works in Python 2.7
The difference is that I want to call method a from within the class. As you see in my firsst example, the
intendation of the call "a('Call a-method')" is inside the class, not outside. My first example works if I comment line #13 (b('aa')).

class TestClass:
    def __init__(self, name):
        self.methoda(name)

    def methodb(self, name):
        print("---b---{}".format(name))

    def methoda(self, name):
        print("---a---{}".format(name))
        self.methodb("aa")

    self.methoda('Call a-method from within class') # This doesn't.

TestClass("Call a-method") # This works
Reply


Messages In This Thread
RE: Call method from another method within a class - by anteboy65 - Sep-11-2019, 01:20 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Accessing method attributes of python class Abedin 6 1,442 Apr-14-2025, 07:02 AM
Last Post: buran
  __eq__ method related problem Tsotne 6 1,179 Mar-09-2025, 03:48 PM
Last Post: Tsotne
  Changing client.get() method type based on size of data... dl0dth 1 827 Jan-02-2025, 08:30 PM
Last Post: dl0dth
  Error in the method "count" for tuple fff 2 981 Nov-24-2024, 03:29 AM
Last Post: fff
  Trying to understand method Giri234 1 839 Oct-04-2024, 02:10 AM
Last Post: deanhystad
  Destructor method adding in string chizzy101010 3 1,099 Sep-03-2024, 12:31 PM
Last Post: chizzy101010
  Difference between method and attribute holding a function ulrich 2 1,086 Jun-30-2024, 08:35 AM
Last Post: snippsat
  comtypes: how to provinde a list of string to a COM method zalanthas 0 1,096 Jun-26-2024, 01:27 PM
Last Post: zalanthas
Question No disconnect method for snowflake.connector ? Calab 0 934 Jun-11-2024, 09:42 PM
Last Post: Calab
  Which method name would you choose? Gribouillis 7 2,075 May-30-2024, 07:05 AM
Last Post: buran

Forum Jump:

User Panel Messages

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