Escrito por estudiantes que aprobaron Inmediatamente disponible después del pago Leer en línea o como PDF ¿Documento equivocado? Cámbialo gratis 4,6 TrustPilot
logo-home
Document preview thumbnail
Vista previa 3 fuera de 29 páginas
Examen

D 522 Exam 1 V2 | D 522 Python for IT Automation | Actual Q&A with Rationale (D522 Exam 1) | Western Governors University

Document preview thumbnail
Vista previa 3 fuera de 29 páginas

D 522 Exam 1 V2 | D 522 Python for IT Automation | Actual Q&A with Rationale (D522 Exam 1) | Western Governors University

Vista previa del contenido

D 522 Exam 1 V2 | D 522 Python for IT
Automation | Actual Q&A with Rationale
(D522 Exam 1) | Western Governors
University
1. When executing a Python script in a Linux environment, which shebang line ensures the

script uses the version of Python 3 installed in the user’s current environment path?

A. #!/bin/python


B. #!/usr/bin/python


C. #!/usr/bin/env python3


D. #/usr/local/python3


Answer: C


Rationale: The shebang line #!/usr/bin/env python3 is the most portable way to locate

the Python interpreter. It searches the user’s PATH environment variable to find the

executable rather than relying on a hardcoded path. This practice is essential for

automation scripts that may run across different Linux distributions or virtual

environments.


2. Which method should be used within the ‘os’ module to check if a specific directory exists

before attempting to create a new folder within it?

A. os.path.isdir()

,B. os.path.exists()


C. os.mkdir()


D. os.path.isfile()


Answer: B


Rationale: The os.path.exists() function returns True if the path exists, regardless of

whether it is a file or a directory. Using this check prevents the script from raising an

OSError when attempting to manipulate a non-existent path. In IT automation, verifying

resource existence is a critical step in error handling and script stability.


3. An IT professional needs to extract all email addresses from a large log file. Which ‘re’

module function is best suited to return all matches as a list of strings?

A. re.search()


B. re.match()


C. re.split()


D. re.findall()


Answer: D


Rationale: The re.findall() function iterates through the entire input string and returns all

non-overlapping matches of a pattern. This is particularly useful for parsing logs where

multiple instances of data, such as emails or IP addresses, need to be captured

, simultaneously. Other functions like re.search() only return the first occurrence

encountered in the text.


4. What is the primary advantage of using the ‘with’ statement when opening a file in Python

for reading or writing?

A. It ensures the file is properly closed even if an exception occurs.


B. It encrypts the file data during the I/O process.


C. It automatically converts the file content into a list.


D. It increases the execution speed of the script by bypassing the OS buffer.


Answer: A


Rationale: The ‘with’ statement acts as a context manager that handles the opening and

closing of file descriptors. This prevents resource leaks which can occur if a script crashes

before reaching an explicit .close() call. In automation, managing file handles correctly is

vital for scripts that process thousands of files.


5. Which command-line argument property in the ‘sys’ module contains the name of the

script being executed?

A. sys.path[0]


B. sys.argv[1]


C. sys.argv[0]


D. sys.cmd

Información del documento

Subido en
16 de julio de 2026
Número de páginas
29
Escrito en
2025/2026
Tipo
Examen
Contiene
Preguntas y respuestas
$16.99

¿Documento equivocado? Cámbialo gratis Dentro de los 14 días posteriores a la compra y antes de descargarlo, puedes elegir otro documento. Puedes gastar el importe de nuevo.
Escrito por estudiantes que aprobaron
Inmediatamente disponible después del pago
Leer en línea o como PDF

Seller avatar
Los indicadores de reputación están sujetos a la cantidad de artículos vendidos por una tarifa y las reseñas que ha recibido por esos documentos. Hay tres niveles: Bronce, Plata y Oro. Cuanto mayor reputación, más podrás confiar en la calidad del trabajo del vendedor.
ScholarsAscend
3.7
(77)
Vendido
453
Seguidores
39
Artículos
29361
Última venta
13 horas hace




Por qué los estudiantes eligen Stuvia

Creado por compañeros estudiantes, verificado por reseñas

Calidad en la que puedes confiar: escrito por estudiantes que aprobaron y evaluado por otros que han usado estos resúmenes.

¿No estás satisfecho? Elige otro documento

¡No te preocupes! Puedes elegir directamente otro documento que se ajuste mejor a lo que buscas.

Paga como quieras, empieza a estudiar al instante

Sin suscripción, sin compromisos. Paga como estés acostumbrado con tarjeta de crédito y descarga tu documento PDF inmediatamente.

Student with book image

“Comprado, descargado y aprobado. Así de fácil puede ser.”

Alisha Student

Preguntas frecuentes