File tree 1 file changed +30
-0
lines changed
1 file changed +30
-0
lines changed Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ package py
7
7
import (
8
8
"errors"
9
9
"strconv"
10
+ "strings"
10
11
)
11
12
12
13
var (
@@ -204,3 +205,32 @@ func loadValue(src Object, data interface{}) error {
204
205
}
205
206
return nil
206
207
}
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