I am getting TypeError: a bytes-like object is required, not 'str' in the following line of code in python3.5.
path = os.getcwd().strip('/n')
Null,userprof = subprocess.check_output('set USERPROFILE', shell=True).split('=')
It means that all data read from the file is returned as bytes objects, not str. We can solve this error by opening the file in read-only mode instead of binary mode, as shown below.
The subprocess. check_output() is used to get the output of the calling program in python. It has 5 arguments; args, stdin, stderr, shell, universal_newlines. The args argument holds the commands that are to be passed as a string.
Bytes-like object in python In Python, a string object is a series of characters that make a string. In the same manner, a byte object is a sequence of bits/bytes that represent data. Strings are human-readable while bytes are computer-readable. Data is converted into byte form before it is stored on a computer.
Decode before using split
funtion
Null,userprof = subprocess.check_output('set USERPROFILE', shell=True).decode('utf-8').split('=')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With