From c89705d6975ffb1e4a3764f4f36bab339f969e8f Mon Sep 17 00:00:00 2001 From: Guido van Rossum Date: Thu, 26 Nov 1992 08:54:07 +0000 Subject: * config.c: Added audioop to lists. * Makefile: change default source directory * socketmodule.c: added getsockname and getpeername * bltinmodule.c: corrected typo in type() error message * Added new built-in functions str() and repr(): repr(x) == `x`; str(x) == x if x is a string, otherwise str(x) == repr(x). * Added joinfields to stropmodule.c (string.join calls joinfields now) --- Python/bltinmodule.c | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) (limited to 'Python/bltinmodule.c') diff --git a/Python/bltinmodule.c b/Python/bltinmodule.c index 18fae5ca75..a6e02bed2d 100644 --- a/Python/bltinmodule.c +++ b/Python/bltinmodule.c @@ -601,13 +601,42 @@ builtin_reload(self, v) return reload_module(v); } +static object * +builtin_repr(self, v) + object *self; + object *v; +{ + if (v == NULL) { + err_badarg(); + return NULL; + } + return reprobject(v); +} + +static object * +builtin_str(self, v) + object *self; + object *v; +{ + if (v == NULL) { + err_badarg(); + return NULL; + } + if (is_stringobject(v)) { + INCREF(v); + return v; + } + else + return reprobject(v); +} + static object * builtin_type(self, v) object *self; object *v; { if (v == NULL) { - err_setstr(TypeError, "type() requres an argument"); + err_setstr(TypeError, "type() requires an argument"); return NULL; } v = (object *)v->ob_type; @@ -642,7 +671,9 @@ static struct methodlist builtin_methods[] = { {"range", builtin_range}, {"raw_input", builtin_raw_input}, {"reload", builtin_reload}, + {"repr", builtin_repr}, {"setattr", builtin_setattr}, + {"str", builtin_str}, {"type", builtin_type}, {NULL, NULL}, }; -- cgit v1.2.1