Implicit lists

Christian Tismer tismer at
Fri Jan 31 17:17:19 CET 2003

Thomas Heller wrote:
> Christian Tismer <tismer at> writes:
>>Here the same, written in some bad Python style,
>>but as a builtin, it would do quite much
>>simplification for argument checking:
>> >>> def iscontainer(obj):
>>... 	try:
>>... 		obj[0:0]   # is sequence
>>... 		try:
>>... 			buffer(obj)
>>... 			return False
>>... 		except:
>>... 			pass
>>... 		return True
>>... 	except:
>>... 		return False
>> >>> iscontainer("")
>> >>> iscontainer(1)
>> >>> iscontainer(())
>>I'm (ab)using the fact that sequences which are
>>no containers usually support the buffer interface.
> This is worse, IMO.
> ctypes' instances support the buffer interface, whether
> they are sequences (or containers) or not.

ctypes is no standard module, and nobody can
foresee arbitrary implementations in extensions.
I said that this is bad Python style, since
I had no other way to express what I mean.
Surely a better concept is needed.

My point is not the implementation but
the fact that we want to decide between
objects which are meant as parameter lists
and which are not.

> All this speaks for Alex'
>     try:
>         obj+''
>     except TypeError:
>         return 
> construct, although I can think of cases where it would
> be problematic.  Think of huge 200 MB strings...

No, this only covers strings and alikes.
This is all sort of hackish and not exactly
expressing what we want to say.

On the 200 MB thing: for strings, forget it, we're lucky.
 >>> a="hallo"
 >>> a+"" is a

ciao - chris

More information about the Python-list mailing list