0

I have the following code, which gave me correct results python 2.7, but as soon as I have ported to python 3, the code doesnt work as expected. I can see correct results in the variable submodule_commit, but they are like b'xxxxxxx\nyyyyyyy' and the split doesnt work anymore. I dont understand, wht is going wrong here. My expectations is a list with submodules.

command = "git submodule status | awk '{print $1}'" submodule_commit = subprocess.check_output(command, shell=True) submodule_commit = submodule_commit.split('\n') 

2 Answers 2

1

I converted the byte string into normal string and it works now.

command = "git submodule status | awk '{print $1}'" submodule_commit = subprocess.check_output(command, shell=True) submodule_commit = str(submodule_commit, 'utf-8') submodule_commit = submodule_commit.split('\n') 
Sign up to request clarification or add additional context in comments.

1 Comment

You can also pass the encoding directly to the check_output command, then it will return a str, e.g. subprocess.check_output(command, shell=True, encoding='utf-8')
0

Try doing submodule_commit.split(b'\n') instead. b'xxxxxxx\nyyyyyyy' is a byte-string and, your splitting method should also taken an input a byte-string. To convert '\n' into a byte-string, you write b'\n' instead. I Let me know if it works. :)

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.