tp_members and T_ULONGLONG ("C" Python modules)

2006-09-01 Thread Gimble
While writing custom modules, I've found the tp_members type entry very useful. (As background, it is a pointer to a constant structure that defines direct access sizes and types of member variables within your custom PyObject ). However, the defined type enumeration (including T_USHORT, T_UINT,

Re: disgrating a list

2006-09-01 Thread Gimble
> def flatten(x): > for i in range(len(x)): > if isinstance(x[i], list): > x[i:i+1] = x[i] I don't think this does what you want. Try [[[1,2,3]]] as a trivial example. A recursive version, that's not as short as yours: def flatten(x): "Recursive example to flatten a

Re: disgrating a list

2006-09-01 Thread Gimble
Or, (to add needed recursion to your simple loop): def flatten(x): "Modified in-place flattening" for i in range(len(x)): if isinstance(x[i], list): x[i:i+1] = flatten(x[i]) return x This version modifies in-place (as yours does), which may or may not be what you w