Skip to content

Commit de8c04a

Browse files
committed
builtin: make print end= and sep= work
1 parent 1a6a2dd commit de8c04a

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

builtin/builtin.go

+16-3
Original file line numberDiff line numberDiff line change
@@ -170,14 +170,27 @@ end: string appended after the last value, default a newline.
170170
flush: whether to forcibly flush the stream.`
171171

172172
func builtin_print(self py.Object, args py.Tuple, kwargs py.StringDict) (py.Object, error) {
173-
// FIXME ignoring file, sep, end and flush
173+
var (
174+
sepObj py.Object = py.String(" ")
175+
endObj py.Object = py.String("\n")
176+
file py.Object
177+
flush py.Object
178+
)
179+
kwlist := []string{"sep", "end", "file", "flush"}
180+
err := py.ParseTupleAndKeywords(nil, kwargs, "|ssOO:print", kwlist, &sepObj, &endObj, &file, &flush)
181+
if err != nil {
182+
return nil, err
183+
}
184+
sep := sepObj.(py.String)
185+
end := endObj.(py.String)
186+
// FIXME ignoring file and flush
174187
for i, v := range args {
175188
fmt.Printf("%v", v)
176189
if i != len(args)-1 {
177-
fmt.Print(" ")
190+
fmt.Print(sep)
178191
}
179192
}
180-
fmt.Print("\n")
193+
fmt.Print(end)
181194
return py.None, nil
182195
}
183196

builtin/tests/builtin.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,9 @@ def gen2():
114114
# FIXME assert pow(2, 10, 17) == 4
115115

116116
doc="print"
117-
# FIXME
117+
# FIXME - need io redirection to test
118+
#print("hello world")
119+
#print(1,2,3,sep=",",end=",\n")
118120

119121
doc="round"
120122
assert round(1.1) == 1.0

0 commit comments

Comments
 (0)