Re: new and updateSome() argument format
Jacob Smullyan <[email protected]> Fri, 20 May 2005 17:34:33 -0400
| Newsgroups | gmane.comp.web.skunkweb |
|---|---|
| Message-ID | <[email protected]> |
On Sat, May 21, 2005 at 06:53:52AM +1000, Steve Kieu wrote:
> Is there any easy way to tell new() to take the same
> parameters format like udateSome({}). The reason is, I
> have written updateSome() and then a new, and wnat to
> copy the param to new from updateSome(). Isn't it more
> convenient?
>
> your comment?
This question really isn't very clear to me, so the below may be
completely off the mark.
First of all, updateSome()'s signature is
updateSome(cls, adict, *args, **fieldData)
while new's signature is
new(cls, **fieldData)
I take it that you are overriding both updateSome and new and want to
reuse the code that modifies the dictionary going in both cases.
Let's say that the method that modifies the dictionary is X. Isn't
the following good enough?
@classmethod
def new(cls, **fieldData):
return BaseClass.new(**X(fieldData))
@classmethod
def updateSome(cls, adict, *args, **fieldData):
return BaseClass.updateSome(X(adict), *args, **fieldData)
(I'm a little uncertain how to use super() in this situation, so I'm
just punting on it.)
If my guess as to what you might have meant wasn't good enough, please
clarify.
Cheers,
js
--
Jacob Smullyan
signature.asc
(application/pgp-signature, 189 B)
-----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.1 (GNU/Linux) iD8DBQFCjlfpuqamFyFXXLIRAs7QAKDJprlfxzBfYcMxE3DL5of7HO5RDgCfTmVE AJ6M3BGer+Mmgz4TVJxBiNg= =X08Z -----END PGP SIGNATURE-----