nerdexam
CompTIA

PT0-002 · Question #293

A penetration tester created the following script to use in an engagement: However, the tester is receiving the following error when trying to run the script: Which of the following is the reason…

The correct answer is C. The sys module was not imported. In Python, 'sys' is a standard library module that must be explicitly imported before use. The variable 'argv' is an attribute of the 'sys' module (accessed as sys.argv), not a standalone module or variable. If the script uses 'sys.argv' without first including 'import sys' at…

Tools and Code Analysis

Question

A penetration tester created the following script to use in an engagement:

However, the tester is receiving the following error when trying to run the script:

Which of the following is the reason for the error?

Exhibits

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

Options

  • AThe sys variable was not defined.
  • BThe argv variable was not defined.
  • CThe sys module was not imported.
  • DThe argv module was not imported.

How the community answered

(39 responses)
  • A
    3% (1)
  • C
    95% (37)
  • D
    3% (1)

Explanation

In Python, 'sys' is a standard library module that must be explicitly imported before use. The variable 'argv' is an attribute of the 'sys' module (accessed as sys.argv), not a standalone module or variable. If the script uses 'sys.argv' without first including 'import sys' at the top, Python raises a NameError: name 'sys' is not defined. The fix is simply to add 'import sys' to the script. Option D is incorrect because 'argv' is not a module - it is an attribute within the sys module.

Topics

#Python scripting#Python modules#NameError#Command-line arguments

Community Discussion

No community discussion yet for this question.

Full PT0-002 Practice