Richard Brodie wrote:
> subscriptable: supports an indexing operator, like a list does.
Right. You can check this e.g. with
hasattr(x, "__getitem__")
because the __getitem__ method is used for indexing.
Daniel
--
http://mail.python.org/mailman/listinfo/python-list
You're maybe searching for epydoc: http://epydoc.sourceforge.net/
--
http://mail.python.org/mailman/listinfo/python-list
Peter Otten wrote:
>
> You should ditch what follows and instead add just
>
> def __iter__(self):
> return iter(self.__keys)
Mhh. I should start learning the builtins ... :)
> To see the problem with your original code (an object serving as its own
> iterator) try the f
Hi!
The sys module provides some useful information, e.g.:
builtin_module_names -- tuple of module names built into this interpreter
version -- the version of this interpreter as a string
version_info -- version information as a tuple
hexversion -- version information encoded as a single integer
Hi!
Never would have thought of this...
I mixed this with the class-version and created a new class derived from
"str" for easier printing and added an iterator:
---
class Enum:
class Type(str):
def __init__(self, name):
self.__name = name
Hi!
You can iterate over the internal dictionary:
>>> class Test:
... def __init__(self):
... self.x = 5
... self.y = 6
... self.z = "Hallo"
...
>>> x = Test()
>>> print x.__dict__
{'y': 6, 'x': 5, 'z': 'Hallo'}
>>> for key, value in x.__dict__.items():
..
Hi!
Try hex:
>>> hex(120)
'0x78'
Consider converting string -> int using the int()-function:
>>> print int.__doc__
int(x[, base]) -> integer
Convert a string or number to an integer, if possible. A floating point
argument will be truncated towards zero (this does not include a string
representa