I have the following issue:
try:
with subprocess.check_call(query):
return 1
except ValueError:
return -1
This code runs a shell script and it's working so far. The script returns 0. Nevertheless I got this error:
with subprocess.check_call(query):
AttributeError: 'int' object has no attribute '__exit__'
so there has to be someting wrong with my try/except block.
asked Aug 16, 2013 at 7:26
Leagis
1751 gold badge5 silver badges14 bronze badges
1 Answer 1
subprocess.check_call() returns an int status code 0, not a context manager. You cannot use it in a with statement.
return subprocess.check_call(query)
Just return the return value of that call. Note that it will not raise a ValueError exception either; it'll raise CalledProcessError if the process exits with a non-zero status code.
Perhaps what you really wanted to use was subprocess.call().
answered Aug 16, 2013 at 7:31
Martijn Pieters
1.1m326 gold badges4.2k silver badges3.5k bronze badges
Sign up to request clarification or add additional context in comments.
Comments
lang-py