Implicit lists

Christian Tismer tismer at tismer.com
Fri Jan 31 11:17:19 EST 2003


Thomas Heller wrote:
> Christian Tismer <tismer at tismer.com> 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("")
>>0
>> >>> iscontainer(1)
>>0
>> >>> iscontainer(())
>>1
>>
>>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