I used exactly the code in my first comment, plus your changes elsewhere in the file, and it worked fine on 3.5. I don't have a 3.6 install that I've proven to work with the whole SpacePy stack but I really doubt that'd be an issue. I'd probably make it: if dtype is str and str is not bytes and type(A) is bytes: A = A.decode() just to make sure what's coming in really needs decoding to str. (At that point the "dtype is str" would probably be redundant.)
You get exceptions indicating the bytes were not being decoded to str when you use the test for Python 3 in the form "str is not bytes" but not in the test on sys.version[0], regardless of the sense of the dtype comparison? Is this failing in a unit test so I can check? (I see that str here will always be str since it's being used more as a flag than the dtype of the actual data.)
It matches the sense of the test in the PR, which I think is backwards...if dtype is str, you're going to call the decode, and str has no decode method in Python 3. There's nothing in the "str is not bytes" that causes an exception on 3.6. I think what you want is actually: if dtype is bytes and str is not bytes: A = A.decode() since that will guarantee A is str, whatever str happens to be.
if dtype is str and str is not bytes: A = A.decode() as mentioned in the last PR. That's an explicit check on what we care about (the flavour of str).
.decode('ascii') will also make a unicode string; that's what .decode does: converts from the Python 2 string type ('bytes' in py3k, 'str' in Python 2) to the Python 3 string type ('unicode' in Python 2, 'str' in Python 3.) If the goal is to make sure it's in a str type regardless, something like: if str is not bytes: headline = headline.decode('ascii') would do the trick (and would fail on non-ASCII characters in Python 3).
The question is, what is the actual encoding of the input? Decoding from ASCII will fail if there are high characters...so it's a matter of what's in the IDL output file. Dan? (How does this "reduce verbosity"?)
Superseded by #3; thanks, and will close this one.
Thanks John! The rebase made it a lot easier to read and Dan's good with the pybats improvements, so I've merged.