summaryrefslogtreecommitdiffstats
path: root/Python/bltinmodule.c
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1992-01-27 16:53:09 (GMT)
committerGuido van Rossum <guido@python.org>1992-01-27 16:53:09 (GMT)
commit33894be6572e1f205359947db8a1025a21f15788 (patch)
tree8b3f481dd2a411cffb01d0fd1c844b1ca676c246 /Python/bltinmodule.c
parentef0a00ec0c8f2fb98616328fa7efdeaf160c0587 (diff)
downloadcpython-33894be6572e1f205359947db8a1025a21f15788.zip
cpython-33894be6572e1f205359947db8a1025a21f15788.tar.gz
cpython-33894be6572e1f205359947db8a1025a21f15788.tar.bz2
Added getattr and setattr built-in functions.
Diffstat (limited to 'Python/bltinmodule.c')
-rw-r--r--Python/bltinmodule.c36
1 files changed, 36 insertions, 0 deletions
diff --git a/Python/bltinmodule.c b/Python/bltinmodule.c
index d5870fe..4b6f301 100644
--- a/Python/bltinmodule.c
+++ b/Python/bltinmodule.c
@@ -210,6 +210,40 @@ builtin_float(self, v)
}
static object *
+builtin_getattr(self, v)
+ object *self;
+ object *v;
+{
+ object *name;
+ if (v == NULL || !is_tupleobject(v) || gettuplesize(v) != 2 ||
+ (name = gettupleitem(v, 1), !is_stringobject(name))) {
+ err_setstr(TypeError,
+ "getattr() arguments must be (object, string)");
+ return NULL;
+ }
+ return getattr(gettupleitem(v, 0), getstringvalue(name));
+}
+
+static object *
+builtin_setattr(self, v)
+ object *self;
+ object *v;
+{
+ object *name;
+ if (v == NULL || !is_tupleobject(v) || gettuplesize(v) != 3 ||
+ (name = gettupleitem(v, 1), !is_stringobject(name))) {
+ err_setstr(TypeError,
+ "setattr() arguments must be (object, string, object)");
+ return NULL;
+ }
+ if (setattr(gettupleitem(v, 0),
+ getstringvalue(name), gettupleitem(v, 2)) != 0)
+ return NULL;
+ INCREF(None);
+ return None;
+}
+
+static object *
builtin_hex(self, v)
object *self;
object *v;
@@ -570,6 +604,7 @@ static struct methodlist builtin_methods[] = {
{"eval", builtin_eval},
{"exec", builtin_exec},
{"float", builtin_float},
+ {"getattr", builtin_getattr},
{"hex", builtin_hex},
{"input", builtin_input},
{"int", builtin_int},
@@ -584,6 +619,7 @@ static struct methodlist builtin_methods[] = {
{"range", builtin_range},
{"raw_input", builtin_raw_input},
{"reload", builtin_reload},
+ {"setattr", builtin_setattr},
{"type", builtin_type},
{NULL, NULL},
};