0% found this document useful (0 votes)
2K views1 page

Context Manager 1

The document defines three functions: writeTo writes a string to a file, archive adds a file to a zip archive, and run_process runs a subprocess and returns the output. writeTo opens a file and writes the input text string. archive opens a zip file and adds the input filename. run_process runs a subprocess, captures the output and error, and returns just the output.

Uploaded by

Senthil Lakshmi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2K views1 page

Context Manager 1

The document defines three functions: writeTo writes a string to a file, archive adds a file to a zip archive, and run_process runs a subprocess and returns the output. writeTo opens a file and writes the input text string. archive opens a zip file and adds the input filename. run_process runs a subprocess, captures the output and error, and returns just the output.

Uploaded by

Senthil Lakshmi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

===================================================================================

===================================================================================
===================================================================================
=======================================

def writeTo(filename, input_text):

with open (filename, 'w') as file:


file.write(input_text)

================================================

# Define 'writeTo' function below, such that


# it writes input_text string to filename.
def writeTo(filename, input_text):
with open (filename, 'w') as file:
file.write(input_text)
# Define the function 'archive' below, such that
# it archives 'filename' into the 'zipfile'
def archive(zfile, filename):
with ZipFile (zfile, 'w') as myzipfile:
myzipfile.write(filename)

================================================

def run_process(cmd_args):
with subprocess.Popen(cmd_args, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
as p:
out, err = p.communicate()
return out

===================================================================================
===================================================================================
===================================================================================
=======================================

You might also like