🌍 Python Programming · flashcards

Python Programming Exception Handling And File Management Flashcards

50 question-and-answer cards covering Exception Handling And File Management as it is examined in Python Programming. 24 of them are printed below, taken from across the deck — no signup, no paywall on the preview.

50Cards in deck
24Free preview
~89Chars per answer
FreePrice

24 sample cards from the Exception Handling And File Management deck

Sampled from the end of the deck, so these are different cards from the ones shown on the syllabus page.

  1. What is the difference between read(), readline(), and readlines()?

    read() returns the whole file as one string, readline() returns one line, readlines() returns a list of all lines.

  2. How do you write a list of strings to a file efficiently in one call?

    Use file.writelines(list_of_strings); note it does not add newline characters automatically.

  3. What method returns or sets the current file position?

    tell() returns the current position; seek(offset) moves to a new position.

  4. What argument controls character encoding when opening a text file, and what is a common safe value?

    The encoding parameter, e.g. open(path, encoding='utf-8'); UTF-8 is the common cross-platform choice.

  5. Which standard module provides object-oriented filesystem path handling?

    pathlib (the Path class).

  6. In pathlib, how do you join a directory Path with a filename?

    Use the / operator: Path('dir') / 'file.txt'.

  7. Which os.path function joins path components portably across operating systems?

    os.path.join()

  8. What is the difference between an absolute path and a relative path?

    An absolute path specifies a location from the filesystem root; a relative path is interpreted relative to the current working directory.

  9. How do you check whether a path exists using os.path or pathlib?

    os.path.exists(path) or Path(path).exists().

  10. How do you create a directory including any missing parent directories?

    os.makedirs(path, exist_ok=True) or Path(path).mkdir(parents=True, exist_ok=True).

  11. Which functions split a path into directory and filename, and into name and extension?

    os.path.split() gives (head, tail); os.path.splitext() gives (root, ext).

  12. What is JSON and which Python module reads/writes it?

    JSON (JavaScript Object Notation) is a text-based data interchange format; the json module handles it.

  13. What is the difference between json.dump/json.load and json.dumps/json.loads?

    dump/load work with file objects; dumps/loads work with strings (s = string).

  14. What Python type does a JSON object deserialize into, and what does a JSON array become?

    A JSON object becomes a dict; a JSON array becomes a list.

  15. Which standard module reads and writes CSV files?

    The csv module (csv.reader, csv.writer, csv.DictReader, csv.DictWriter).

  16. Why should you open a CSV file with newline='' when using the csv module?

    To prevent the csv module's row handling from conflicting with universal newline translation, which can otherwise insert blank rows on some platforms.

  17. Which module parses and writes YAML, and is it in the standard library?

    PyYAML (the yaml module); it is a third-party package, not in the standard library.

  18. What is the purpose of the Python debugger pdb, and how do you set a breakpoint inline?

    pdb is the interactive debugger for stepping through code; use breakpoint() (Python 3.7+) or import pdb; pdb.set_trace().

  19. Name three common pdb commands and what they do.

    n (next line), s (step into call), c (continue); also l (list source) and p (print expression).

  20. What standard module provides flexible, level-based diagnostic output preferable to print debugging?

    The logging module, with levels DEBUG, INFO, WARNING, ERROR, CRITICAL.

  21. What is unit testing, and which two frameworks are common in Python?

    Unit testing verifies individual components in isolation; common frameworks are unittest (standard library) and pytest (third-party).

  22. In pytest, how are test functions and assertions typically written?

    Test functions are named test_* and use plain Python assert statements, e.g. 'def test_add(): assert add(2,3) == 5'.

  23. What is a docstring and how is it accessed at runtime?

    A docstring is a string literal as the first statement in a module, class, or function; it is accessible via the object's __doc__ attribute or help().

  24. What does PEP 8 govern, and what indentation does it recommend?

    PEP 8 is Python's style guide for readable, consistent code; it recommends 4 spaces per indentation level (no tabs).

What this deck covers

This deck covers the Exception Handling And File Management portion of the Python Programming syllabus in question-and-answer form. Browse the full Python Programming syllabus to see how it fits with the rest.

Answers are written to be recallable, not just readable — averaging about 89 characters, which is long enough to carry the reasoning and short enough to say out loud.

A deck like this earns its keep on the second and third pass. Read the syllabus first so you know the shape of the subject, then use the cards to find the specific facts that have not stuck.

Exception Handling And File Management flashcards FAQ

How many Exception Handling And File Management flashcards are in this Python Programming deck?

50 cards. This page previews 24 of them, sampled evenly across the deck so you can judge the difficulty before installing anything.

Are these Python Programming flashcards free?

Yes. The preview here is free to read with no signup, and the full 50-card deck is free inside the Examius app.

What do the Exception Handling And File Management cards cover?

They follow the Exception Handling And File Management portion of the Python Programming syllabus, in question-and-answer form.

How should I use these flashcards?

Read the syllabus first so you know the shape of the subject, then drill the deck. Examius schedules each card with spaced repetition, so cards you keep missing come back sooner and ones you know drift further apart.