Execute the following code in Python3
>>>Importsubprocess>>> p=subprocess. Popen ('ls', shell=true,stdout=subprocess. PIPE)>>> d=P.stdout.read ()>>>DB'agent2.0.tgz\njdk1.8.0_152\njdk-8u152-linux-x64.tar.gz\nmha4mysql-manager-0.56-0.el6.noarch.rpm\ nmha4mysql-node-0.56-0.el6.noarch.rpm\nscript.rpm.sh\nscripts\n'>>> D.split ('\ n') Traceback (most recent): File"<stdin>", Line 1,inch<module>TypeError:'Str'Does notSupport the Buffer interface
Buffer interface allows an object to expose information about its underlying buffer, an example of using buffer interface is the write () method of the file object, and any object that exports a series of bytes through buffer interface can be written to the file. Python3 only supports bytes and Unicode encoding, and no longer supports STR
The workaround is to convert STR to tytes, and then back to the STR type after processing
>>> p=subprocess. Popen ('ls', shell=true,stdout=subprocess. PIPE)>>> d=P.stdout.read ()>>> d.split (Bytes ('\ n','UTF8')) [B'agent2.0.tgz'B'jdk1.8.0_152'B'jdk-8u152-linux-x64.tar.gz'B'mha4mysql-manager-0.56-0.el6.noarch.rpm'B'mha4mysql-node-0.56-0.el6.noarch.rpm'B'script.rpm.sh'B'Scripts'B"']
Encountered Python3 incompatible with Python2 's place