String encodes an Unicode object and returns the result as a Python bytes object converted to the Go string.
()
| 269 | |
| 270 | // String encodes an Unicode object and returns the result as a Python bytes object converted to the Go string. |
| 271 | func (ob *PyObject) String() string { |
| 272 | if ob.rawptr == nil { |
| 273 | return "" |
| 274 | } |
| 275 | repr := C.PyObject_Str(ob.rawptr) |
| 276 | if repr == nil { |
| 277 | return "" |
| 278 | } |
| 279 | defer C.Py_DecRef(repr) |
| 280 | s := C.PyUnicode_AsEncodedString(repr, encoding, codecErrors) |
| 281 | if s == nil { |
| 282 | return "invalid Unicode string" |
| 283 | } |
| 284 | defer C.Py_DecRef(s) |
| 285 | return C.GoString(C.PyBytes_AsString(s)) |
| 286 | } |
| 287 | |
| 288 | // StringSlice returns this object as a string slice. |
| 289 | func (ob *PyObject) StringSlice() []string { |