Python Forum
How to pass variables from one class to another
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to pass variables from one class to another
#9
Look at the below
class One:
    def get_a_life(self):
        paris = Two.give_a_life(self)
        return paris

class Two:
    def give_a_life(self):
        return "What we will always have"

onesie = One()
print(onesie.get_a_life())
Output:
What we will always have
Class One calls class Two before class Two has been defined. Is that what you are wanting?
Reply


Messages In This Thread
RE: How to pass variables from one class to another - by jefsummers - Sep-22-2021, 07:49 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Unchangeable variables in a class? Calab 12 1,560 Sep-15-2023, 07:15 PM
Last Post: deanhystad
  How to pass encrypted pass to pyodbc script tester_V 0 875 Jul-27-2023, 12:40 AM
Last Post: tester_V
  Class variables and Multiprocessing(or concurrent.futures.ProcessPoolExecutor) Tomli 5 3,907 Nov-12-2021, 09:55 PM
Last Post: snippsat
  Acess variables from class samuelbachorik 3 1,906 Aug-20-2021, 02:55 PM
Last Post: deanhystad
Exclamation win32com: How to pass a reference object into a COM server class Alfalfa 3 4,903 Jul-26-2021, 06:25 PM
Last Post: Alfalfa
  Do I have to pass 85 variables to function? Milfredo 10 4,331 Sep-26-2020, 10:13 PM
Last Post: Milfredo
  Pass by object reference when does it behave like pass by value or reference? mczarnek 2 2,572 Sep-07-2020, 08:02 AM
Last Post: perfringo
  Class variables menator01 2 2,020 Jun-04-2020, 04:23 PM
Last Post: Yoriz
  Question about naming variables in class methods sShadowSerpent 1 2,024 Mar-25-2020, 04:51 PM
Last Post: ndc85430
  Pass by reference vs Pass by value leodavinci1990 1 2,222 Nov-20-2019, 02:05 AM
Last Post: jefsummers

Forum Jump:

User Panel Messages

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