You seem to be on the right track

Luis N wrote:
I'm wondering how I can turn a variable number of keyword arguments
passed to a class into variables for use in said class:

#This so doesn't work

It is helpful if you tell us what you tried and how it failed...


class SomethingLikeThis: def __init__(self, **kwargs): self.kwargs = kwargs

    def show(self):
        for k in self.kwargs.keys():
            v = selfkwargs.get(k)

This line does have an error; it is missing a '.': v = self.kwargs.get(k)

print v

This works for me: class SomethingLikeThis: def __init__(self, **kwargs): self.kwargs = kwargs

    def show(self):
        for k, v in self.kwargs.items():
            print k, '=', v

s = SomethingLikeThis(a='abc', num=1, phone='888-555-1212')
s.show()

If that doesn't do what you want then give us more details.

Kent
_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to