โ† All POC Flashcard Decks

Automation & Scripting Flashcards

7 cards from real POC practice questions. Tap to flip, then mark Knew It or Still Learning โ€” missed cards come back until you master them.

Read the first 7 Automation & Scripting flashcards as text
  1. Which Python module provides the `run()` function for executing shell commands and capturing output?

    Answer: subprocess

    `subprocess.run()` executes a command, waits for it to complete, and returns a CompletedProcess instance with stdout/stderr.

  2. In a Python automation script, what does `subprocess.run(['ls', '-la'], capture_output=True, text=True)` return?

    Answer: A CompletedProcess object with stdout and stderr as strings

    `capture_output=True` and `text=True` make `run()` return a CompletedProcess whose `.stdout` and `.stderr` are decoded strings.

  3. Which `schedule` library method runs all pending scheduled jobs?

    Answer: schedule.run_pending()

    `schedule.run_pending()` checks all registered jobs and runs any whose next run time has passed.

  4. What is the purpose of the `watchdog` library in Python automation?

    Answer: Monitor filesystem events and trigger callbacks

    `watchdog` monitors file system changes (create, modify, delete) and dispatches events to handler classes.

  5. Which context manager ensures a file is properly closed even if an exception occurs during reading?

    Answer: `with open(filename) as f:`

    The `with` statement calls `__exit__` on the file object, closing it automatically even if an exception is raised inside the block.

  6. In Python's `argparse`, what does `add_argument('--verbose', action='store_true')` do?

    Answer: Sets the attribute to True when the flag is present, False otherwise

    `action='store_true'` sets the destination attribute to `True` when the flag appears and `False` when it is absent.

  7. Which Python function sends an HTTP GET request when using the `requests` library?

    Answer: requests.get()

    `requests.get(url)` sends an HTTP GET request and returns a `Response` object with `.status_code`, `.text`, and `.json()` method.