S
Steven D'Aprano
When you call a new-style class, the __new__ method is called with the
user-supplied arguments, followed by the __init__ method with the same
arguments.
I would like to modify the arguments after the __new__ method is called
but before the __init__ method, somewhat like this:
.... def __new__(cls, *args):
.... print "__new__", args
.... x = object.__new__(cls)
.... args = ['spam spam spam']
.... return x
.... def __init__(self, *args):
.... print "__init__", args # hope to get 'spam spam spam'
.... return None
but naturally it doesn't work:
__new__ ('spam and eggs', 'tomato', 'beans are off')
__init__ ('spam and eggs', 'tomato', 'beans are off')
Is there any way to do this, or am I all outta luck?
user-supplied arguments, followed by the __init__ method with the same
arguments.
I would like to modify the arguments after the __new__ method is called
but before the __init__ method, somewhat like this:
.... def __new__(cls, *args):
.... print "__new__", args
.... x = object.__new__(cls)
.... args = ['spam spam spam']
.... return x
.... def __init__(self, *args):
.... print "__init__", args # hope to get 'spam spam spam'
.... return None
but naturally it doesn't work:
__new__ ('spam and eggs', 'tomato', 'beans are off')
__init__ ('spam and eggs', 'tomato', 'beans are off')
Is there any way to do this, or am I all outta luck?