Bytes vs Strings (Was Re: [Tutor] Error Python version 3.6 does not support this syntax)
Rhodri James
rhodri at kynesim.co.uk
Thu Nov 29 14:48:51 EST 2018
On 29/11/2018 19:20, srinivasan wrote:
> With the below code snippet, I am seeing the below error, I am using
> python 3.6, could you please what could be the issue?
[snip]
> Traceback (most recent call last):
> File "/home/srinivasan/Downloads/bt_tests/qa/test_library/bt_tests.py",
> line 169, in <module>
> bl.start_scan()
> File "/home/srinivasan/Downloads/bt_tests/qa/test_library/bt_tests.py",
> line 32, in start_scan
> out = self.get_output("scan on")
> File "/home/srinivasan/Downloads/bt_tests/qa/test_library/bt_tests.py",
> line 27, in get_output
> return self.child.before.split("\r\n")
> TypeError: a bytes-like object is required, not 'str'
The traceback tells you that you are expected to provide a "bytes"
string rather than a unicode (normal) string. I would guess that's
because pexpect is returning a byte string in self.child.before. You
should:
a) check the pexpect documentation to see if that's correct
b) supply self.child.before.split() with a byte string
c) seriously consider whether you are making life hard for yourself
You appear to regard Python as a language you can use to run shell
commands and parse their output. Have you looked to see if there are
existing Python modules that will Just Do The Work for you and avoid all
this faffing about?
--
Rhodri James *-* Kynesim Ltd
More information about the Python-list
mailing list