Skip to content

Do's and Dont's

Giovanni Torres edited this page Aug 19, 2017 · 1 revision

Do encode before passing to C, otherwise, end up with the following error in Py3

  • TypeError: expected bytes, str found

Do encode before passing to Python function, which ultimately passes variable to C function:

  • AttributeError: 'bytes' object has no attribute 'encode'

Don't use temporary python variables when passing to a C function

  • Obtaining char * from temporary Python value

Do convert dict.values() to a list before returning for python 3 compat

  • TypeError: 'dict_values' object does not support indexing

Do decode subprocess output to avoid error in Py3

  • TypeError: 'str' does not support the buffer interface

Question: should something return 'No' instead of False, or vice versa? or map int 1 -> bool True, etc.