mirror of https://github.com/01-edu/public.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
1.6 KiB
1.6 KiB
skip_secrets
Instructions
You need to write a script, skip_secrets.py
, that will be able to decrypt the text coming form a specific file.
The script will receive a file name as the first argument, check if the file is readable, filter the content by skipping all the lines containing pineapple
and save the result in a file out.txt
If the file passed as argument is not readable or the number of arguments is not the one expected, the script should exit with a status code 1
.
Usage
Below an example of how the script is supposed to work:
$ cat -e file.txt
A normal pizza $
Another normal pizza$
A pizza with pineapple$
Yet another very normal and delicious pizza$
$ python3 skip_secrets.py
$ echo $?
1
$ python3 skip_secrets.py file.txt
$ cat out.txt
A normal pizza $
Another normal pizza$
A pizza with pineapple$
Yet another very normal and delicious pizza$
$
Hints
- It is possible to read arguments passed to a python script using the
sys
module. Here is an example of script (argv.py
):
import sys
for argv in sys.argv:
print(argv)
And its output:
$ python3 argv.py 1 2 3 something else
argv.py
1
2
3
something
else
$
- It is possible to interrupt the execution of a script and returning a status code different from
0
with the functionexit()
. For example, consider the followingexample.py
:
exit(1)
This would be the result:
$ python3 example.py
$ echo $? # check the status code
1