GetStringSlice returns the nth argument as a slice of string values.
(n uint8)
| 57 | |
| 58 | // GetStringSlice returns the nth argument as a slice of string values. |
| 59 | func (args PyArgs) GetStringSlice(n uint8) ([]string, error) { |
| 60 | ob := C.PyArg_ParseList((*C.PyObject)(unsafe.Pointer(args)), C.int(n)) |
| 61 | if ob == nil { |
| 62 | return nil, errTypeNotList |
| 63 | } |
| 64 | l := int(C.PyList_Size(ob)) |
| 65 | s := make([]string, l) |
| 66 | for i := 0; i < l; i++ { |
| 67 | item := C.PyList_GetItem(ob, C.longlong(i)) |
| 68 | if item == nil { |
| 69 | continue |
| 70 | } |
| 71 | isUnicode := bool(C.Py_IsUnicode(item)) |
| 72 | if !isUnicode { |
| 73 | continue |
| 74 | } |
| 75 | s[i] = fromRawOb(item).String() |
| 76 | } |
| 77 | return s, nil |
| 78 | } |
| 79 | |
| 80 | // GetSlice returns the nth argument as a slice of generic values. |
| 81 | func (args PyArgs) GetSlice(n uint8) ([]interface{}, error) { |