File tree Expand file tree Collapse file tree 1 file changed +30
-0
lines changed Expand file tree Collapse file tree 1 file changed +30
-0
lines changed Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ package py
77import (
88 "errors"
99 "strconv"
10+ "strings"
1011)
1112
1213var (
@@ -204,3 +205,32 @@ func loadValue(src Object, data interface{}) error {
204205 }
205206 return nil
206207}
208+
209+ // Println prints the provided strings to gpython's stdout.
210+ func Println (self Object , args ... string ) bool {
211+ sysModule , err := self .(* Module ).Context .GetModule ("sys" )
212+ if err != nil {
213+ return false
214+ }
215+ stdout := sysModule .Globals ["stdout" ]
216+ write , err := GetAttrString (stdout , "write" )
217+ if err != nil {
218+ return false
219+ }
220+ call , ok := write .(I__call__ )
221+ if ! ok {
222+ return false
223+ }
224+ for _ , v := range args {
225+ if ! strings .Contains (v , "\n " ) {
226+ v += " "
227+ }
228+ _ , err := call .M__call__ (Tuple {String (v )}, nil )
229+ if err != nil {
230+ return false
231+ }
232+
233+ }
234+ _ , err = call .M__call__ (Tuple {String ("\n " )}, nil ) // newline
235+ return err == nil
236+ }
You can’t perform that action at this time.
0 commit comments