r""" Converts any given object to utf-8 encoded string. >>> safestr('hello') 'hello' >>> safestr(2) '2'
(obj, encoding="utf-8")
| 352 | |
| 353 | |
| 354 | def safestr(obj, encoding="utf-8"): |
| 355 | r""" |
| 356 | Converts any given object to utf-8 encoded string. |
| 357 | |
| 358 | >>> safestr('hello') |
| 359 | 'hello' |
| 360 | >>> safestr(2) |
| 361 | '2' |
| 362 | """ |
| 363 | |
| 364 | if obj and hasattr(obj, "__next__"): |
| 365 | return [safestr(i) for i in obj] |
| 366 | else: |
| 367 | return str(obj) |
| 368 | |
| 369 | |
| 370 | # Since Python3, utf-8 encoded strings and unicode strings are the same thing |
no outgoing calls
no test coverage detected