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
Which Python module allows you to read and write `.env` files for environment variable management?
Answer: dotenv (python-dotenv)
`python-dotenv` loads variables from a `.env` file into `os.environ` using `load_dotenv()`.
What does `os.walk(top)` yield when traversing a directory tree?
Answer: Tuples of (dirpath, dirnames, filenames) for each directory
`os.walk()` yields `(dirpath, dirnames, filenames)` tuples, where `dirnames` are subdirectory names and `filenames` are file names in that directory.
In Selenium WebDriver automation, which method waits up to a maximum time for a condition to be true before throwing a TimeoutException?
Answer: WebDriverWait(driver, timeout).until(condition)
`WebDriverWait` polls the condition function every 500ms and raises `TimeoutException` if the condition isn't met within the timeout.
Which `pathlib.Path` method creates a directory and all missing intermediate parents without error if the directory already exists?
Answer: Path.mkdir(parents=True, exist_ok=True)
`parents=True` creates intermediate directories and `exist_ok=True` suppresses the `FileExistsError` if the target already exists.
When automating CSV processing, which Python module provides `DictReader` to iterate rows as dictionaries?
Answer: csv
`csv.DictReader` reads each row using the first row's headers as keys, returning `OrderedDict` objects per row.
What is the correct way to pass environment variables to a subprocess in Python?
Answer: subprocess.run(cmd, env={'KEY': 'val'})
The `env` parameter of `subprocess.run()` accepts a dict that completely replaces the inherited environment for the child process.
Which Python built-in function converts command-line arguments stored in `sys.argv` into a structured format?
Answer: argparse.ArgumentParser().parse_args()
`ArgumentParser().parse_args()` reads from `sys.argv[1:]` by default and returns a `Namespace` object with typed, validated attributes.