0
class neato:

    def __init__(self):
        self.dance = "I love to dance yadayaadadad!"

def main():
    happyDance()
    print(happy.dance)

def happyDance():
    happy = neato()


main()

I would rather like to be able to reference my class objects module wide. This is a little experiment of that. Is there any way to do this? Currently, the code prints a name error.

1 Answers1

0

You could return the instance of Neato made in the function happyDance:

class neato:

    def __init__(self):
        self.dance = "I love to dance yadayaadadad!"

def main():
    happy = happyDance()
    print(happy.dance)

def happyDance():
    return neato()


main()
Reblochon Masque
  • 35,405
  • 10
  • 55
  • 80