[Python-checkins] CVS: python/dist/src/Lib string.py,1.46,1.47

Adrian Eyre a.eyre@optichrome.com
Fri, 11 Feb 2000 17:32:53 -0000

>     AE> I figured that this applies to lists, tuples and strings. See
>     AE> previous post for examples.
> And any class that acts like a sequence has to implement a join()
> method too.

If they want to override the default.

Assuming format:

<sequence>.join(separator = " ") -> <string>

The default would be something like:

PyObject* PySequence_Join(PyObject* self, PyObject* args)
	char* sep = " ";
	int len, idx;
	PyObject* str, result, pysep;

	assert(PySequence_Check(self)); /* not sure if this is needed */

	if (!PyArg_ParseTuple(args, "|s", &sep))
		return NULL;

	pysep = PyString_FromString(sep);
	result = PyString_New();

	len = PyObject_Length(self);
	for (idx = 0; idx < len; idx++)
		str = PyObject_Str(PySequence_GetItem(self, idx));
		PyString_ConcatAndDel(result, str);
		if (idx != len)
			PyString_Concat(result, pysep);


	return result;

So, providing their sequence implements getitem, and items can
be stringified, they won't need to override the default.

Adrian Eyre <a.eyre@optichrome.com> - http://www.optichrome.com