tuple to list to tuple conversion
W Isaac Carroll
icarroll at pobox.com
Tue Jun 3 11:54:57 CEST 2003
Vinoo vasudevan wrote:
> Can someone tell me what I'm doing wrong here?
> I have a method that needs to call other methods like this:
> def mymethod(self, methodname, params):
> apply(methodname, params)
> params is already a tuple. I needed to add a few more parameters
> inside 'mymethod' so I did this:
> params = tuple((list(params)).append(something))
> when params is an empty tuple to begin with, the stmt sets it to None
> instead of (something,)
> However the following works regardless of whether params is empty:
> x = list(params)
> params = tuple(x)
The append() method modifies the list in-place and returns None in
accordance with standard Python procedure.
Instead of changing to a list, just create a new tuple by concatenation:
def mymethod(self, methodname, params):
Just make sure that "something" is a tuple and everything will work fine.
More information about the Python-list