nerdexam
CompTIA

PT0-002 · Question #610

During a penetration test, a security consultant needs to parse the contents of a CSV file. Which of the following Python code snippets would help the consultant accomplish this task?

The correct answer is B. Option B. The correct Python code snippet for parsing a CSV file involves using the built-in csv module to handle its structured data effectively.

Tools and Code Analysis

Question

During a penetration test, a security consultant needs to parse the contents of a CSV file. Which of the following Python code snippets would help the consultant accomplish this task?

Exhibits

PT0-002 question #610 exhibit 1
PT0-002 question #610 exhibit 2

Options

  • AOption A
  • BOption B
  • COption C
  • DOption D

How the community answered

(42 responses)
  • B
    93% (39)
  • C
    2% (1)
  • D
    5% (2)

Why each option

The correct Python code snippet for parsing a CSV file involves using the built-in `csv` module to handle its structured data effectively.

AOption A

Simply splitting lines by a comma using `line.split(',')` is an unreliable method for parsing CSVs, as it fails to properly handle quoted commas, embedded newlines, or other complexities of the CSV format.

BOption BCorrect

Python's built-in `csv` module is specifically designed for parsing CSV (Comma Separated Values) files, providing reliable methods like `csv.reader` to correctly handle delimiters, quoted fields, and line endings, processing each row as a list of strings.

COption C

The `json` module in Python is used for parsing JSON (JavaScript Object Notation) formatted data, not CSV files.

DOption D

While the `pandas` library can read CSV files, it is an external dependency. The built-in `csv` module provides the fundamental and direct Python solution for parsing CSV contents without requiring additional installations.

Concept tested: Python CSV file parsing

Source: https://docs.python.org/3/library/csv.html

Topics

#Python#CSV parsing#Data processing#Scripting

Community Discussion

No community discussion yet for this question.

Full PT0-002 Practice