Commit 21633f74 authored by Franck Thollard's avatar Franck Thollard
Browse files

providing a 'nicer' format for logging. Handling ret code in suprocess example

parent 4cb98a81
......@@ -317,20 +317,19 @@
``` python
import subprocess
def call_bash(commands):
return subprocess.call(['/bin/bash', '-c', commands])
call_bash("""
echo Hello
grep toto -r
ret = call_bash("""
echo Hello; cat /tmp/jfdkfjdk
""")
if ret == 0:
print("command succeed")
else:
print(f"command failed with return code {ret}")
```
%%%% Output: execute_result
0
%% Cell type:markdown id: tags:
### argparse - Parser for command-line options, arguments and sub-commands
argparse is the right tool to develop a command line script with options and help.
......@@ -345,12 +344,13 @@
``` python
import logging
log_level = logging.INFO # to get information messages
# log_level = logging.WARNING # no information messages
logging.basicConfig(format='%(message)s',
level=log_level)
logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
level=logging.INFO)
level=log_level)
thing = 'beer'
logging.info('Would you like to have a "%s"?', thing)
```
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment