Code Monkey home page Code Monkey logo

py-create-file-from-terminal's Introduction

Create file from terminal

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 -d flag passed, means all items after this flag are parts of the path.

python create_file.py -d dir1 dir2 - creates directory dir1/dir2 inside current directory.

  • If only -f flag 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: stop

This creates file file.txt inside current directory with content:

2022-02-01 14:41:10
1 Line1 content
2 Line2 content
3 Line3 content

App 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: stop
2022-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 -d and -f flags 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: stop

Creates 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 content

It would be relevant to use:

  • sys.argv to read arguments from the terminal
  • os.makedirs to create directories
  • .strftime() method for datetime.now() to make timestamp more beautiful.

Note: Check your code using this checklist before pushing your solution.

py-create-file-from-terminal's People

Contributors

masterpieceelbow avatar abnormaltype avatar danylott avatar y-havryliv avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.