@@ -29,7 +29,7 @@ func init() {
29
29
py .MustNewMethod ("compile" , builtin_compile , 0 , compile_doc ),
30
30
// py.MustNewMethod("delattr", builtin_delattr, 0, delattr_doc),
31
31
// py.MustNewMethod("dir", builtin_dir, 0, dir_doc),
32
- // py.MustNewMethod("divmod", builtin_divmod, 0, divmod_doc),
32
+ py .MustNewMethod ("divmod" , builtin_divmod , 0 , divmod_doc ),
33
33
// py.MustNewMethod("eval", builtin_eval, 0, eval_doc),
34
34
// py.MustNewMethod("exec", builtin_exec, 0, exec_doc),
35
35
// py.MustNewMethod("format", builtin_format, 0, format_doc),
@@ -553,6 +553,23 @@ func builtin_compile(self py.Object, args py.Tuple, kwargs py.StringDict) (py.Ob
553
553
return result , nil
554
554
}
555
555
556
+ const divmod_doc = `divmod(x, y) -> (quotient, remainder)
557
+
558
+ Return the tuple ((x-x%y)/y, x%y). Invariant: div*y + mod == x.`
559
+
560
+ func builtin_divmod (self py.Object , args py.Tuple ) (py.Object , error ) {
561
+ var x , y py.Object
562
+ err := py .UnpackTuple (args , nil , "divmod" , 2 , 2 , & x , & y )
563
+ if err != nil {
564
+ return nil , err
565
+ }
566
+ q , r , err := py .DivMod (x , y )
567
+ if err != nil {
568
+ return nil , err
569
+ }
570
+ return py.Tuple {q , r }, nil
571
+ }
572
+
556
573
const len_doc = `len(object) -> integer
557
574
558
575
Return the number of items of a sequence or mapping.`
0 commit comments