Using Python to Interact with the Operating System

Lakukan tugas rumah & ujian kamu dengan baik sekarang menggunakan Quizwiz!

A company is looking at automating one of their internal processes and wants to determine if automating a process would save labor time this year. The company uses the formula [time_to_automate < (time_to_perform * amount_of_times_done) to decide whether automation is worthwhile. The process normally takes about 10 minutes every week. The automation process itself will take 40 hours total to complete. Using the formula, how many weeks will it be before the company starts saving time on the process?

240 weeks

What is pip an example of?

A Python package manager

What is grep?

A command-line regex tool

When capturing regex groups, what datatype does the groups method return?

A tuple

At a manufacturing plant, an employee spends several minutes each hour noting uptime and downtime for each of the machines they are running. Which of the following ideas would best automate this process?

Add an analog Internet of Things (IoT) module to each machine, in order to detect their power states, and write a script that records uptime and downtime, reporting hourly

Which of the following operating systems is compatible with Python 3?

All of the above(Redhat Linux, Microsoft Windows, Apple MacOS)

When a test is codified into its own software, what kind of test is it?

Automatic test

In what type of test is the code not transparent?

Black-box test

You can verify that software code behaves correctly using test ___.

Cases

When your IDE automatically creates an indent for you, this is known as what?

Code completion

Which type of programming language is read and converted to machine code before runtime, allowing for more efficient code?

Compiled language

What type of object does a run function return?

CompletedProcess

Which of the following statements are true regarding Bash and Python? [Check all that apply]

Complex scripts are better suited to Python. Python can more easily operate on strings, lists, and dictionaries. If a script requires testing, Python is preferable.

Which keyword will return control back to the top of a loop when iterating through logs?

Continue

In order to use the writerows() function of DictWriter() to write a list of dictionaries to each line of a CSV file, what steps should we take? (Check all that apply)

Create an instance of the DictWriter() class Write the fieldnames parameter into the first row using writeheader() Open the csv file using with open

What does the copy method of os.environ do?

Creates a new dictionary of environment variables

Which of the following is a data structure that can be used to count how many times a specific error appears in a log?

Dictionary

What is the most basic way of testing a script?

Different parameters with expected results.

Which of the following are valid methods to prevent silent automation errors? (Check all that apply)

Email notifications about errors Internal issue tracker entries Regular consistency checks

Which module can you load in a Python script to take advantage of star [*] like in BASH?

Glob

Verifying an automation script works well with the overall system and external entities describes what type of test?

Integration test

_____ ensures that any success or failure of a unit test is caused by the behavior of the unit in question, and doesn't result from some external factor.

Isolation

One important aspect of automation is forensic value. Which of the following statements describes this term correctly?

It is important for automated processes to leave extensive logs so when errors occur, they can be properly investigated.

How can you change the current working directory where a command will be executed?

Use the cwd parameter.

Which of the following is true about unpacking values into variables when reading rows of a CSV file? (Check all that apply)

We need the same amount of variables as there are columns of data in the CSV Rows can be read using both csv.reader and csv.DictReader An instance of the reader class must be created first

Which of the following are true about parsing log files? (Select all that apply.)

You should parse log files line by line. It is efficient to ignore lines that don't contain the information we need. We have to open() the log files first.

When using the run command of the subprocess module, what parameter, when set to True, allows us to store the output of a system command?

capture_output

The _____ command lets us take only bits of each line using a field delimiter.

cut

Which command does the while loop initiate a task(s) after?

do

Which command will print out the exit value of a script that just ran successfully?

echo $?

Which of the following commands will output a list of all files in the current directory?

echo *

Conditional execution is based on the _____ of commands.

exit status

Which command will create a new environment variable?

export

Which line is correctly written to start a FOR loop with a sample.txt file?

for file in sample.txt; do

An employee at a technical support company is required to collate reports into a single file and send that file via email three times a day, five days a week for one month, on top of his other duties. It takes him about 15 minutes each time. He has discovered a way to automate the process, but it will take him at least 10 hours to code the automation script. Which of the following equations will help them decide whether it's worth automating the process?

if [10 hours to automate < (15 minutes * 60 times per month)] then automate

Which statements are true about input and raw_input in Python 2? (select all that apply)

input performs basic math operations. raw_input gets a string from the user.

In Linux, what command is used to display the contents of a directory?

ls

Which of the following methods from the os module will create a new directory?

mkdir()

Which of the following is not an IDE or code editor?

pip

If we want to check to see what version of Python is installed, what would we type into the command line? Select all that apply.

python -V python --version

When searching log files using regex, which regex statement will search for the alphanumeric word "IP" followed by one or more digits wrapped in parentheses using a capturing group?

r("IP \((\d+)\)$"

When using regular expressions, which of the following expressions uses a reserved character that can represent any single character?

re.findall(f.n, text)

Which of the following is NOT a function of the Python regex module?

re.grep()

The more complex our code becomes, the more value the use of _____ provides in managing errors.

software testing

You have created a Python script to read a log of users running CRON jobs. The script needs to accept a command line argument for the path to the log file. Which line of code accomplishes this?

syslog=sys.argv[1]

The opening square bracket ([), when combined with the closing square bracket (]), is an alias for which command?

test

What command evaluates the conditions received on exit to verify that there is an exit status of 0 when the conditions are true, and 1 when they are false?

test

Using _____ simplifies the testing process, allowing us to verify the program's behavior repeatedly with many possible values.

test cases

Which of the following commands will redirect errors in a script to a file?

user@ubuntu:~$ ./calculator.py 2> error_file.txt

Which of the following Bash lines contains the condition of taking an action when n is less than or equal to 9?

while [ $n -le 9 ]; do

What type of software testing is used to verify the software's ability to behave well under significantly stressed testing conditions?

Load test

The circumflex [^] and the dollar sign [$] are anchor characters. What do these anchor characters do in regex?

Match the start and end of a line

What does the plus character [+] do in regex?

Matches one or more occurrences of the character before it

If we are analyzing a file's contents to correctly structure its data, what action are we performing on the file?

Parsing

Which of the following is the most modern, up-to-date version of Python?

Python 3

What does the "r" before the pattern string in re.search(r"Py.*n", sample.txt) indicate?

Raw strings

A test that is written after a bug has been identified in order to ensure the bug doesn't show up again later is called _____

Regression test

When running a kill command in a terminal, what type of signal is being sent to the process?

SIGTERM

Which I/O stream are we using when we use the input function to accept user input in a Python script?

STDIN

_____ are tokens delivered to running processes to indicate a desired action.

Signals

When using regex, some characters represent particular types of characters. Some examples are the dollar sign, the circumflex, and the dot wildcard. What are these characters collectively known as?

Special characters

What is required in order to read from standard input using Python?

Stdin file object from sys module

What does the PATH variable do?

Tells the operating system where to find executables

When a child process is run using the subprocess module, which of the following are true? (check all that apply)

The child process is run in a secondary environment. The parent process is blocked while the child process finishes. Control is returned to the parent process when the child process ends.

What is the meaning of an exit code of 0?

The program ended successfully.


Set pelajaran terkait

SPCH-1321 2807 1 CHAPTER 6 OVERLOOK

View Set

AIS EXAM 2 CHAPTER QUESTION (CH6, CH8, CH9, CH11)

View Set