Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python

quick question for pythonistas

Ok so lets say i have a dunder init fuction :

def init(self, **kwargs): for key, vlue in kwargs.items(): setattr(self, key, value)

and i add a kwargs arguments

how would i include in the dunder str function to print it :

def str(self): return '{}'.format(###kwargs in here###)

1 Answer

Steven Parker
Steven Parker
243,318 Points

Would this do?

    def __str__(self):
        return ', '.join("%s: %s" % item for item in self.__dict__.items())