forked from go-python/gpython
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrange_repr19.go
More file actions
38 lines (32 loc) · 727 Bytes
/
range_repr19.go
File metadata and controls
38 lines (32 loc) · 727 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// Copyright 2018 The go-python Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// +build !go1.10
// Range object
package py
import "bytes"
func (r *Range) repr() (Object, error) {
var b bytes.Buffer
b.WriteString("range(")
start, err := ReprAsString(r.Start)
if err != nil {
return nil, err
}
stop, err := ReprAsString(r.Stop)
if err != nil {
return nil, err
}
b.WriteString(start)
b.WriteString(", ")
b.WriteString(stop)
if r.Step != 1 {
step, err := ReprAsString(r.Step)
if err != nil {
return nil, err
}
b.WriteString(", ")
b.WriteString(step)
}
b.WriteString(")")
return String(b.String()), nil
}