How do I call system commands in Python?

I have been exploring how to run external commands or system commands using Python. When I’m trying to call a system command using Python, I’m getting an error in my code. I have tried many methods to resolve it, but they are not working.


The error that I’m getting:

total 4
-rw-r--r-- 1 jovyan root 838 Apr  3 19:46 Dockerfile
AttributeError                            Traceback (most recent call last)
Cell In[1], line 4
      1 import subprocess
      3 result =['ls', '-l'], check=True)
----> 4 print(result.returnstatus)

AttributeError: 'CompletedProcess' object has no attribute 'returnstatus'

Here is my code below:

Can someone highlight the mistake that I’m making in the code? You can provide many other alternative methods that help me in executing the external commands.