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.
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
Options
- AOption A
- BOption B
- COption C
- DOption D
How the community answered
(42 responses)- B93% (39)
- C2% (1)
- D5% (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.
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.
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.
The `json` module in Python is used for parsing JSON (JavaScript Object Notation) formatted data, not CSV files.
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
Community Discussion
No community discussion yet for this question.

