I like partition() but maybe even better would be if strings supported slicing by string indices.
key, sep, val = 'foo = 32'.partition('=') would be: key, val = 'foo = 32'[:'='], 'foo = 32'['=':] To me it feels very natural to extend Python's slices to string indices and would cover most of partition()'s use cases. The if sep: idiom of parition() could be solved by throwing an IndexError: e.g: _, sep, port = host.partition(':') if sep: try: int(port) except ValueError: becomes: try: port = host[':':] int(port) except IndexError: pass except ValueError: An advantage of using slices would be that you could specify both a beginning and ending string like this: >>> s 'http://192.168.12.22:8080' >>> s['http://':':'] '192.168.12.22' Sorry if this idea has already been discussed. -- mvh Björn _______________________________________________ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com