Skip to content

Commit

Permalink
builtin: make print end= and sep= work
Browse files Browse the repository at this point in the history
  • Loading branch information
ncw committed Jun 13, 2015
1 parent 1a6a2dd commit de8c04a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
19 changes: 16 additions & 3 deletions builtin/builtin.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,14 +170,27 @@ end: string appended after the last value, default a newline.
flush: whether to forcibly flush the stream.`

func builtin_print(self py.Object, args py.Tuple, kwargs py.StringDict) (py.Object, error) {
// FIXME ignoring file, sep, end and flush
var (
sepObj py.Object = py.String(" ")
endObj py.Object = py.String("\n")
file py.Object
flush py.Object
)
kwlist := []string{"sep", "end", "file", "flush"}
err := py.ParseTupleAndKeywords(nil, kwargs, "|ssOO:print", kwlist, &sepObj, &endObj, &file, &flush)
if err != nil {
return nil, err
}
sep := sepObj.(py.String)
end := endObj.(py.String)
// FIXME ignoring file and flush
for i, v := range args {
fmt.Printf("%v", v)
if i != len(args)-1 {
fmt.Print(" ")
fmt.Print(sep)
}
}
fmt.Print("\n")
fmt.Print(end)
return py.None, nil
}

Expand Down
4 changes: 3 additions & 1 deletion builtin/tests/builtin.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,9 @@ def gen2():
# FIXME assert pow(2, 10, 17) == 4

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

doc="round"
assert round(1.1) == 1.0
Expand Down

0 comments on commit de8c04a

Please sign in to comment.