Read the guideline before starting.
Create an app create_file.py that takes directory path, file name, file
content from the terminal and creates file. There should be flags -d or -f:
- If only
-dflag passed, it means all items after this flag are treated as separate parts of the path (i.e., individual directory names).
When using -d, each directory name must be passed as a separate argument, e.g.,
python create_file.py -d dir1 dir2 - creates directory dir1/dir2 inside
current directory.
- If only
-fflag passed, means first item is the file name.
python create_file.py -f file.txt
After pressing Enter it creates file file.txt and then terminal should
ask you to input content lines until you input "stop":
Enter content line: Line1 content
Enter content line: Line2 content
Enter content line: Line3 content
Enter content line: stopThis creates file file.txt inside current directory with content:
2022-02-01 14:41:10
1 Line1 content
2 Line2 content
3 Line3 contentApp should add current timestamp at the top and number lines. If file.txt
already exists it should add content below:
python create_file.py -f file.txt
Enter content line: Another line1 content
Enter content line: Another line2 content
Enter content line: Another line3 content
Enter content line: stop2022-02-01 14:41:10
1 Line1 content
2 Line2 content
3 Line3 content
2022-02-01 14:46:01
1 Another line1 content
2 Another line2 content
3 Another line3 content- If both
-dand-fflags passed, app creates directory and file with content inside this directory.
python create_file.py -d dir1 dir2 -f file.txt
Enter content line: Line1 content
Enter content line: Line2 content
Enter content line: Line3 content
Enter content line: stopCreates directory dir1/dir2 inside current directory and
creates file file.txt
inside that directory with content:
dir1/dir2/file.txt:
2022-02-01 14:46:01
1 Line1 content
2 Line2 content
3 Line3 contentIt would be relevant to use:
sys.argvto read arguments from the terminalos.makedirsto create directories.strftime()method fordatetime.now()to make timestamp more beautiful.