class_id
stringlengths 15
16
| class_code
stringlengths 519
6.03k
| skeleton
stringlengths 561
4.56k
| method_code
stringlengths 44
1.82k
| method_summary
stringlengths 15
540
|
---|---|---|---|---|
ClassEval_97_sum | class Words2Numbers:
"""
The class provides a text-to-number conversion utility, allowing conversion of written numbers (in words) to their numerical representation.
"""
def __init__(self):
self.numwords = {}
self.units = [
"zero", "one", "two", "three", "four", "five", "six", "seven", "eight",
"nine", "ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen",
"sixteen", "seventeen", "eighteen", "nineteen",
]
self.tens = ["", "", "twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty", "ninety"]
self.scales = ["hundred", "thousand", "million", "billion", "trillion"]
self.numwords["and"] = (1, 0)
for idx, word in enumerate(self.units):
self.numwords[word] = (1, idx)
for idx, word in enumerate(self.tens):
self.numwords[word] = (1, idx * 10)
for idx, word in enumerate(self.scales):
self.numwords[word] = (10 ** (idx * 3 or 2), 0)
self.ordinal_words = {'first': 1, 'second': 2, 'third': 3, 'fifth': 5, 'eighth': 8, 'ninth': 9, 'twelfth': 12}
self.ordinal_endings = [('ieth', 'y'), ('th', '')]
def is_valid_input(self, textnum):
"""
Check if the input text contains only valid words that can be converted into numbers.
:param textnum: The input text containing words representing numbers.
:return: True if input is valid, False otherwise.
>>> w2n = Words2Numbers()
>>> w2n.is_valid_input("thirty-two")
False
"""
textnum = textnum.replace('-', ' ')
for word in textnum.split():
if word in self.ordinal_words:
continue
else:
for ending, replacement in self.ordinal_endings:
if word.endswith(ending):
word = "%s%s" % (word[:-len(ending)], replacement)
if word not in self.numwords:
return False
return True | class Words2Numbers:
"""
The class provides a text-to-number conversion utility, allowing conversion of written numbers (in words) to their numerical representation.
"""
def __init__(self):
"""
Initialize the word lists and dictionaries required for conversion
"""
self.numwords = {}
self.units = [
"zero", "one", "two", "three", "four", "five", "six", "seven", "eight",
"nine", "ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen",
"sixteen", "seventeen", "eighteen", "nineteen",
]
self.tens = ["", "", "twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty", "ninety"]
self.scales = ["hundred", "thousand", "million", "billion", "trillion"]
self.numwords["and"] = (1, 0)
for idx, word in enumerate(self.units):
self.numwords[word] = (1, idx)
for idx, word in enumerate(self.tens):
self.numwords[word] = (1, idx * 10)
for idx, word in enumerate(self.scales):
self.numwords[word] = (10 ** (idx * 3 or 2), 0)
self.ordinal_words = {'first': 1, 'second': 2, 'third': 3, 'fifth': 5, 'eighth': 8, 'ninth': 9, 'twelfth': 12}
self.ordinal_endings = [('ieth', 'y'), ('th', '')]
def is_valid_input(self, textnum):
"""
Check if the input text contains only valid words that can be converted into numbers.
:param textnum: The input text containing words representing numbers.
:return: True if input is valid, False otherwise.
>>> w2n = Words2Numbers()
>>> w2n.is_valid_input("thirty-two")
False
""" | def text2int(self, textnum):
textnum = textnum.replace('-', ' ')
current = result = 0
curstring = ""
onnumber = False
for word in textnum.split():
if word in self.ordinal_words:
scale, increment = (1, self.ordinal_words[word])
current = current * scale + increment
onnumber = True
else:
for ending, replacement in self.ordinal_endings:
if word.endswith(ending):
word = "%s%s" % (word[:-len(ending)], replacement)
if word not in self.numwords:
if onnumber:
curstring += repr(result + current) + " "
curstring += word + " "
result = current = 0
onnumber = False
else:
scale, increment = self.numwords[word]
current = current * scale + increment
if scale > 100:
result += current
current = 0
onnumber = True
if onnumber:
curstring += repr(result + current)
return curstring | Convert the word string to the corresponding integer string |
ClassEval_97_sum | class Words2Numbers:
"""
The class provides a text-to-number conversion utility, allowing conversion of written numbers (in words) to their numerical representation.
"""
def __init__(self):
self.numwords = {}
self.units = [
"zero", "one", "two", "three", "four", "five", "six", "seven", "eight",
"nine", "ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen",
"sixteen", "seventeen", "eighteen", "nineteen",
]
self.tens = ["", "", "twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty", "ninety"]
self.scales = ["hundred", "thousand", "million", "billion", "trillion"]
self.numwords["and"] = (1, 0)
for idx, word in enumerate(self.units):
self.numwords[word] = (1, idx)
for idx, word in enumerate(self.tens):
self.numwords[word] = (1, idx * 10)
for idx, word in enumerate(self.scales):
self.numwords[word] = (10 ** (idx * 3 or 2), 0)
self.ordinal_words = {'first': 1, 'second': 2, 'third': 3, 'fifth': 5, 'eighth': 8, 'ninth': 9, 'twelfth': 12}
self.ordinal_endings = [('ieth', 'y'), ('th', '')]
def text2int(self, textnum):
"""
Convert the word string to the corresponding integer string
:param textnum: string, the word string to be converted
:return: string, the final converted integer string
>>> w2n = Words2Numbers()
>>> w2n.text2int("thirty-two")
"32"
"""
textnum = textnum.replace('-', ' ')
current = result = 0
curstring = ""
onnumber = False
for word in textnum.split():
if word in self.ordinal_words:
scale, increment = (1, self.ordinal_words[word])
current = current * scale + increment
onnumber = True
else:
for ending, replacement in self.ordinal_endings:
if word.endswith(ending):
word = "%s%s" % (word[:-len(ending)], replacement)
if word not in self.numwords:
if onnumber:
curstring += repr(result + current) + " "
curstring += word + " "
result = current = 0
onnumber = False
else:
scale, increment = self.numwords[word]
current = current * scale + increment
if scale > 100:
result += current
current = 0
onnumber = True
if onnumber:
curstring += repr(result + current)
return curstring
def is_valid_input(self, textnum):
textnum = textnum.replace('-', ' ')
for word in textnum.split():
if word in self.ordinal_words:
continue
else:
for ending, replacement in self.ordinal_endings:
if word.endswith(ending):
word = "%s%s" % (word[:-len(ending)], replacement)
if word not in self.numwords:
return False
return True | class Words2Numbers:
"""
The class provides a text-to-number conversion utility, allowing conversion of written numbers (in words) to their numerical representation.
"""
def __init__(self):
"""
Initialize the word lists and dictionaries required for conversion
"""
self.numwords = {}
self.units = [
"zero", "one", "two", "three", "four", "five", "six", "seven", "eight",
"nine", "ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen",
"sixteen", "seventeen", "eighteen", "nineteen",
]
self.tens = ["", "", "twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty", "ninety"]
self.scales = ["hundred", "thousand", "million", "billion", "trillion"]
self.numwords["and"] = (1, 0)
for idx, word in enumerate(self.units):
self.numwords[word] = (1, idx)
for idx, word in enumerate(self.tens):
self.numwords[word] = (1, idx * 10)
for idx, word in enumerate(self.scales):
self.numwords[word] = (10 ** (idx * 3 or 2), 0)
self.ordinal_words = {'first': 1, 'second': 2, 'third': 3, 'fifth': 5, 'eighth': 8, 'ninth': 9, 'twelfth': 12}
self.ordinal_endings = [('ieth', 'y'), ('th', '')]
def text2int(self, textnum):
"""
Convert the word string to the corresponding integer string
:param textnum: string, the word string to be converted
:return: string, the final converted integer string
>>> w2n = Words2Numbers()
>>> w2n.text2int("thirty-two")
"32"
"""
def is_valid_input(self, textnum):
"""
Check if the input text contains only valid words that can be converted into numbers.
:param textnum: The input text containing words representing numbers.
:return: True if input is valid, False otherwise.
>>> w2n = Words2Numbers()
>>> w2n.is_valid_input("thirty-two")
False
""" | def is_valid_input(self, textnum):
textnum = textnum.replace('-', ' ')
for word in textnum.split():
if word in self.ordinal_words:
continue
else:
for ending, replacement in self.ordinal_endings:
if word.endswith(ending):
word = "%s%s" % (word[:-len(ending)], replacement)
if word not in self.numwords:
return False
return True | Check if the input text contains only valid words that can be converted into numbers. |
ClassEval_98_sum | import xml.etree.ElementTree as ET
class XMLProcessor:
"""
This is a class as XML files handler, including reading, writing, processing as well as finding elements in a XML file.
"""
def __init__(self, file_name):
self.file_name = file_name
self.root = None
def write_xml(self, file_name):
"""
Writes the XML data to the specified file.
:param file_name: string, the name of the file to write the XML data.
:return: bool, True if the write operation is successful, False otherwise.
>>> xml_processor = XMLProcessor('test.xml')
>>> root = xml_processor.read_xml()
>>> success = xml_processor.write_xml('output.xml')
>>> print(success)
True
"""
try:
tree = ET.ElementTree(self.root)
tree.write(file_name)
return True
except:
return False
def process_xml_data(self, file_name):
"""
Modifies the data in XML elements and writes the updated XML data to a new file.
:param file_name: string, the name of the file to write the modified XML data.
:return: bool, True if the write operation is successful, False otherwise.
>>> xml_processor = XMLProcessor('test.xml')
>>> root = xml_processor.read_xml()
>>> success = xml_processor.process_xml_data('processed.xml')
>>> print(success)
True
"""
for element in self.root.iter('item'):
text = element.text
element.text = text.upper()
return self.write_xml(file_name)
def find_element(self, element_name):
"""
Finds the XML elements with the specified name.
:param element_name: string, the name of the elements to find.
:return: list, a list of found elements with the specified name.
>>> xml_processor = XMLProcessor('test.xml')
>>> root = xml_processor.read_xml()
>>> items = xml_processor.find_element('item')
>>> for item in items:
>>> print(item.text)
apple
banana
orange
"""
elements = self.root.findall(element_name)
return elements | import xml.etree.ElementTree as ET
class XMLProcessor:
"""
This is a class as XML files handler, including reading, writing, processing as well as finding elements in a XML file.
"""
def __init__(self, file_name):
"""
Initialize the XMLProcessor object with the given file name.
:param file_name:string, the name of the XML file to be processed.
"""
self.file_name = file_name
self.root = None
def write_xml(self, file_name):
"""
Writes the XML data to the specified file.
:param file_name: string, the name of the file to write the XML data.
:return: bool, True if the write operation is successful, False otherwise.
>>> xml_processor = XMLProcessor('test.xml')
>>> root = xml_processor.read_xml()
>>> success = xml_processor.write_xml('output.xml')
>>> print(success)
True
"""
def process_xml_data(self, file_name):
"""
Modifies the data in XML elements and writes the updated XML data to a new file.
:param file_name: string, the name of the file to write the modified XML data.
:return: bool, True if the write operation is successful, False otherwise.
>>> xml_processor = XMLProcessor('test.xml')
>>> root = xml_processor.read_xml()
>>> success = xml_processor.process_xml_data('processed.xml')
>>> print(success)
True
"""
def find_element(self, element_name):
"""
Finds the XML elements with the specified name.
:param element_name: string, the name of the elements to find.
:return: list, a list of found elements with the specified name.
>>> xml_processor = XMLProcessor('test.xml')
>>> root = xml_processor.read_xml()
>>> items = xml_processor.find_element('item')
>>> for item in items:
>>> print(item.text)
apple
banana
orange
""" | def read_xml(self):
try:
tree = ET.parse(self.file_name)
self.root = tree.getroot()
return self.root
except:
return None | Reads the XML file and returns the root element. |
ClassEval_98_sum | import xml.etree.ElementTree as ET
class XMLProcessor:
"""
This is a class as XML files handler, including reading, writing, processing as well as finding elements in a XML file.
"""
def __init__(self, file_name):
self.file_name = file_name
self.root = None
def read_xml(self):
"""
Reads the XML file and returns the root element.
:return: Element, the root element of the XML file.
>>> xml_processor = XMLProcessor('test.xml')
>>> root_element = xml_processor.read_xml()
>>> print(root_element)
<Element 'root' at 0x7f8e3b7eb180>
"""
try:
tree = ET.parse(self.file_name)
self.root = tree.getroot()
return self.root
except:
return None
def process_xml_data(self, file_name):
"""
Modifies the data in XML elements and writes the updated XML data to a new file.
:param file_name: string, the name of the file to write the modified XML data.
:return: bool, True if the write operation is successful, False otherwise.
>>> xml_processor = XMLProcessor('test.xml')
>>> root = xml_processor.read_xml()
>>> success = xml_processor.process_xml_data('processed.xml')
>>> print(success)
True
"""
for element in self.root.iter('item'):
text = element.text
element.text = text.upper()
return self.write_xml(file_name)
def find_element(self, element_name):
"""
Finds the XML elements with the specified name.
:param element_name: string, the name of the elements to find.
:return: list, a list of found elements with the specified name.
>>> xml_processor = XMLProcessor('test.xml')
>>> root = xml_processor.read_xml()
>>> items = xml_processor.find_element('item')
>>> for item in items:
>>> print(item.text)
apple
banana
orange
"""
elements = self.root.findall(element_name)
return elements | import xml.etree.ElementTree as ET
class XMLProcessor:
"""
This is a class as XML files handler, including reading, writing, processing as well as finding elements in a XML file.
"""
def __init__(self, file_name):
"""
Initialize the XMLProcessor object with the given file name.
:param file_name:string, the name of the XML file to be processed.
"""
self.file_name = file_name
self.root = None
def read_xml(self):
"""
Reads the XML file and returns the root element.
:return: Element, the root element of the XML file.
>>> xml_processor = XMLProcessor('test.xml')
>>> root_element = xml_processor.read_xml()
>>> print(root_element)
<Element 'root' at 0x7f8e3b7eb180>
"""
def process_xml_data(self, file_name):
"""
Modifies the data in XML elements and writes the updated XML data to a new file.
:param file_name: string, the name of the file to write the modified XML data.
:return: bool, True if the write operation is successful, False otherwise.
>>> xml_processor = XMLProcessor('test.xml')
>>> root = xml_processor.read_xml()
>>> success = xml_processor.process_xml_data('processed.xml')
>>> print(success)
True
"""
def find_element(self, element_name):
"""
Finds the XML elements with the specified name.
:param element_name: string, the name of the elements to find.
:return: list, a list of found elements with the specified name.
>>> xml_processor = XMLProcessor('test.xml')
>>> root = xml_processor.read_xml()
>>> items = xml_processor.find_element('item')
>>> for item in items:
>>> print(item.text)
apple
banana
orange
""" | def write_xml(self, file_name):
try:
tree = ET.ElementTree(self.root)
tree.write(file_name)
return True
except:
return False | Writes the XML data to the specified file. |
ClassEval_98_sum | import xml.etree.ElementTree as ET
class XMLProcessor:
"""
This is a class as XML files handler, including reading, writing, processing as well as finding elements in a XML file.
"""
def __init__(self, file_name):
self.file_name = file_name
self.root = None
def read_xml(self):
"""
Reads the XML file and returns the root element.
:return: Element, the root element of the XML file.
>>> xml_processor = XMLProcessor('test.xml')
>>> root_element = xml_processor.read_xml()
>>> print(root_element)
<Element 'root' at 0x7f8e3b7eb180>
"""
try:
tree = ET.parse(self.file_name)
self.root = tree.getroot()
return self.root
except:
return None
def write_xml(self, file_name):
"""
Writes the XML data to the specified file.
:param file_name: string, the name of the file to write the XML data.
:return: bool, True if the write operation is successful, False otherwise.
>>> xml_processor = XMLProcessor('test.xml')
>>> root = xml_processor.read_xml()
>>> success = xml_processor.write_xml('output.xml')
>>> print(success)
True
"""
try:
tree = ET.ElementTree(self.root)
tree.write(file_name)
return True
except:
return False
def find_element(self, element_name):
"""
Finds the XML elements with the specified name.
:param element_name: string, the name of the elements to find.
:return: list, a list of found elements with the specified name.
>>> xml_processor = XMLProcessor('test.xml')
>>> root = xml_processor.read_xml()
>>> items = xml_processor.find_element('item')
>>> for item in items:
>>> print(item.text)
apple
banana
orange
"""
elements = self.root.findall(element_name)
return elements | import xml.etree.ElementTree as ET
class XMLProcessor:
"""
This is a class as XML files handler, including reading, writing, processing as well as finding elements in a XML file.
"""
def __init__(self, file_name):
"""
Initialize the XMLProcessor object with the given file name.
:param file_name:string, the name of the XML file to be processed.
"""
self.file_name = file_name
self.root = None
def read_xml(self):
"""
Reads the XML file and returns the root element.
:return: Element, the root element of the XML file.
>>> xml_processor = XMLProcessor('test.xml')
>>> root_element = xml_processor.read_xml()
>>> print(root_element)
<Element 'root' at 0x7f8e3b7eb180>
"""
def write_xml(self, file_name):
"""
Writes the XML data to the specified file.
:param file_name: string, the name of the file to write the XML data.
:return: bool, True if the write operation is successful, False otherwise.
>>> xml_processor = XMLProcessor('test.xml')
>>> root = xml_processor.read_xml()
>>> success = xml_processor.write_xml('output.xml')
>>> print(success)
True
"""
def find_element(self, element_name):
"""
Finds the XML elements with the specified name.
:param element_name: string, the name of the elements to find.
:return: list, a list of found elements with the specified name.
>>> xml_processor = XMLProcessor('test.xml')
>>> root = xml_processor.read_xml()
>>> items = xml_processor.find_element('item')
>>> for item in items:
>>> print(item.text)
apple
banana
orange
""" | def process_xml_data(self, file_name):
for element in self.root.iter('item'):
text = element.text
element.text = text.upper()
return self.write_xml(file_name) | Modifies the data in XML elements and writes the updated XML data to a new file. |
ClassEval_98_sum | import xml.etree.ElementTree as ET
class XMLProcessor:
"""
This is a class as XML files handler, including reading, writing, processing as well as finding elements in a XML file.
"""
def __init__(self, file_name):
self.file_name = file_name
self.root = None
def read_xml(self):
"""
Reads the XML file and returns the root element.
:return: Element, the root element of the XML file.
>>> xml_processor = XMLProcessor('test.xml')
>>> root_element = xml_processor.read_xml()
>>> print(root_element)
<Element 'root' at 0x7f8e3b7eb180>
"""
try:
tree = ET.parse(self.file_name)
self.root = tree.getroot()
return self.root
except:
return None
def write_xml(self, file_name):
"""
Writes the XML data to the specified file.
:param file_name: string, the name of the file to write the XML data.
:return: bool, True if the write operation is successful, False otherwise.
>>> xml_processor = XMLProcessor('test.xml')
>>> root = xml_processor.read_xml()
>>> success = xml_processor.write_xml('output.xml')
>>> print(success)
True
"""
try:
tree = ET.ElementTree(self.root)
tree.write(file_name)
return True
except:
return False
def process_xml_data(self, file_name):
"""
Modifies the data in XML elements and writes the updated XML data to a new file.
:param file_name: string, the name of the file to write the modified XML data.
:return: bool, True if the write operation is successful, False otherwise.
>>> xml_processor = XMLProcessor('test.xml')
>>> root = xml_processor.read_xml()
>>> success = xml_processor.process_xml_data('processed.xml')
>>> print(success)
True
"""
for element in self.root.iter('item'):
text = element.text
element.text = text.upper()
return self.write_xml(file_name)
def find_element(self, element_name):
elements = self.root.findall(element_name)
return elements | import xml.etree.ElementTree as ET
class XMLProcessor:
"""
This is a class as XML files handler, including reading, writing, processing as well as finding elements in a XML file.
"""
def __init__(self, file_name):
"""
Initialize the XMLProcessor object with the given file name.
:param file_name:string, the name of the XML file to be processed.
"""
self.file_name = file_name
self.root = None
def read_xml(self):
"""
Reads the XML file and returns the root element.
:return: Element, the root element of the XML file.
>>> xml_processor = XMLProcessor('test.xml')
>>> root_element = xml_processor.read_xml()
>>> print(root_element)
<Element 'root' at 0x7f8e3b7eb180>
"""
def write_xml(self, file_name):
"""
Writes the XML data to the specified file.
:param file_name: string, the name of the file to write the XML data.
:return: bool, True if the write operation is successful, False otherwise.
>>> xml_processor = XMLProcessor('test.xml')
>>> root = xml_processor.read_xml()
>>> success = xml_processor.write_xml('output.xml')
>>> print(success)
True
"""
def process_xml_data(self, file_name):
"""
Modifies the data in XML elements and writes the updated XML data to a new file.
:param file_name: string, the name of the file to write the modified XML data.
:return: bool, True if the write operation is successful, False otherwise.
>>> xml_processor = XMLProcessor('test.xml')
>>> root = xml_processor.read_xml()
>>> success = xml_processor.process_xml_data('processed.xml')
>>> print(success)
True
"""
def find_element(self, element_name):
"""
Finds the XML elements with the specified name.
:param element_name: string, the name of the elements to find.
:return: list, a list of found elements with the specified name.
>>> xml_processor = XMLProcessor('test.xml')
>>> root = xml_processor.read_xml()
>>> items = xml_processor.find_element('item')
>>> for item in items:
>>> print(item.text)
apple
banana
orange
""" | def find_element(self, element_name):
elements = self.root.findall(element_name)
return elements | Finds the XML elements with the specified name. |
ClassEval_99_sum | import zipfile
class ZipFileProcessor:
"""
This is a compressed file processing class that provides the ability to read and decompress compressed files
"""
def __init__(self, file_name):
self.file_name = file_name
def extract_all(self, output_path):
"""
Extract all zip files and place them in the specified path
:param output_path: string, The location of the extracted file
:return: True or False, representing whether the extraction operation was successful
>>> zfp = ZipFileProcessor("aaa.zip")
>>> zfp.extract_all("result/aaa")
"""
try:
with zipfile.ZipFile(self.file_name, 'r') as zip_file:
zip_file.extractall(output_path)
return True
except:
return False
def extract_file(self, file_name, output_path):
"""
Extract the file with the specified name from the zip file and place it in the specified path
:param file_name:string, The name of the file to be uncompressed
:param output_path:string, The location of the extracted file
:return: True or False, representing whether the extraction operation was successful
>>> zfp = ZipFileProcessor("aaa.zip")
>>> zfp.extract_file("bbb.txt", "result/aaa")
"""
try:
with zipfile.ZipFile(self.file_name, 'r') as zip_file:
zip_file.extract(file_name, output_path)
return True
except:
return False
def create_zip_file(self, files, output_file_name):
"""
Compress the specified file list into a zip file and place it in the specified path
:param files:list of string, List of files to compress
:param output_file_name: string, Specified output path
:return:True or False, representing whether the compression operation was successful
>>> zfp = ZipFileProcessor("aaa.zip")
>>> zfp.create_zip_file(["bbb.txt", "ccc,txt", "ddd.txt"], "output/bcd")
"""
try:
with zipfile.ZipFile(output_file_name, 'w') as zip_file:
for file in files:
zip_file.write(file)
return True
except:
return False | import zipfile
class ZipFileProcessor:
"""
This is a compressed file processing class that provides the ability to read and decompress compressed files
"""
def __init__(self, file_name):
"""
Initialize file name
:param file_name:string
"""
self.file_name = file_name
def extract_all(self, output_path):
"""
Extract all zip files and place them in the specified path
:param output_path: string, The location of the extracted file
:return: True or False, representing whether the extraction operation was successful
>>> zfp = ZipFileProcessor("aaa.zip")
>>> zfp.extract_all("result/aaa")
"""
def extract_file(self, file_name, output_path):
"""
Extract the file with the specified name from the zip file and place it in the specified path
:param file_name:string, The name of the file to be uncompressed
:param output_path:string, The location of the extracted file
:return: True or False, representing whether the extraction operation was successful
>>> zfp = ZipFileProcessor("aaa.zip")
>>> zfp.extract_file("bbb.txt", "result/aaa")
"""
def create_zip_file(self, files, output_file_name):
"""
Compress the specified file list into a zip file and place it in the specified path
:param files:list of string, List of files to compress
:param output_file_name: string, Specified output path
:return:True or False, representing whether the compression operation was successful
>>> zfp = ZipFileProcessor("aaa.zip")
>>> zfp.create_zip_file(["bbb.txt", "ccc,txt", "ddd.txt"], "output/bcd")
""" | def read_zip_file(self):
try:
zip_file = zipfile.ZipFile(self.file_name, 'r')
return zip_file
except:
return None | Get open file object |
ClassEval_99_sum | import zipfile
class ZipFileProcessor:
"""
This is a compressed file processing class that provides the ability to read and decompress compressed files
"""
def __init__(self, file_name):
self.file_name = file_name
def read_zip_file(self):
"""
Get open file object
:return:If successful, returns the open file object; otherwise, returns None
>>> zfp = ZipFileProcessor("aaa.zip")
>>> file = zfp.read_zip_file()
"""
try:
zip_file = zipfile.ZipFile(self.file_name, 'r')
return zip_file
except:
return None
def extract_file(self, file_name, output_path):
"""
Extract the file with the specified name from the zip file and place it in the specified path
:param file_name:string, The name of the file to be uncompressed
:param output_path:string, The location of the extracted file
:return: True or False, representing whether the extraction operation was successful
>>> zfp = ZipFileProcessor("aaa.zip")
>>> zfp.extract_file("bbb.txt", "result/aaa")
"""
try:
with zipfile.ZipFile(self.file_name, 'r') as zip_file:
zip_file.extract(file_name, output_path)
return True
except:
return False
def create_zip_file(self, files, output_file_name):
"""
Compress the specified file list into a zip file and place it in the specified path
:param files:list of string, List of files to compress
:param output_file_name: string, Specified output path
:return:True or False, representing whether the compression operation was successful
>>> zfp = ZipFileProcessor("aaa.zip")
>>> zfp.create_zip_file(["bbb.txt", "ccc,txt", "ddd.txt"], "output/bcd")
"""
try:
with zipfile.ZipFile(output_file_name, 'w') as zip_file:
for file in files:
zip_file.write(file)
return True
except:
return False | import zipfile
class ZipFileProcessor:
"""
This is a compressed file processing class that provides the ability to read and decompress compressed files
"""
def __init__(self, file_name):
"""
Initialize file name
:param file_name:string
"""
self.file_name = file_name
def read_zip_file(self):
"""
Get open file object
:return:If successful, returns the open file object; otherwise, returns None
>>> zfp = ZipFileProcessor("aaa.zip")
>>> file = zfp.read_zip_file()
"""
def extract_file(self, file_name, output_path):
"""
Extract the file with the specified name from the zip file and place it in the specified path
:param file_name:string, The name of the file to be uncompressed
:param output_path:string, The location of the extracted file
:return: True or False, representing whether the extraction operation was successful
>>> zfp = ZipFileProcessor("aaa.zip")
>>> zfp.extract_file("bbb.txt", "result/aaa")
"""
def create_zip_file(self, files, output_file_name):
"""
Compress the specified file list into a zip file and place it in the specified path
:param files:list of string, List of files to compress
:param output_file_name: string, Specified output path
:return:True or False, representing whether the compression operation was successful
>>> zfp = ZipFileProcessor("aaa.zip")
>>> zfp.create_zip_file(["bbb.txt", "ccc,txt", "ddd.txt"], "output/bcd")
""" | def extract_all(self, output_path):
try:
with zipfile.ZipFile(self.file_name, 'r') as zip_file:
zip_file.extractall(output_path)
return True
except:
return False | Extract all zip files and place them in the specified path |
ClassEval_99_sum | import zipfile
class ZipFileProcessor:
"""
This is a compressed file processing class that provides the ability to read and decompress compressed files
"""
def __init__(self, file_name):
self.file_name = file_name
def read_zip_file(self):
"""
Get open file object
:return:If successful, returns the open file object; otherwise, returns None
>>> zfp = ZipFileProcessor("aaa.zip")
>>> file = zfp.read_zip_file()
"""
try:
zip_file = zipfile.ZipFile(self.file_name, 'r')
return zip_file
except:
return None
def extract_all(self, output_path):
"""
Extract all zip files and place them in the specified path
:param output_path: string, The location of the extracted file
:return: True or False, representing whether the extraction operation was successful
>>> zfp = ZipFileProcessor("aaa.zip")
>>> zfp.extract_all("result/aaa")
"""
try:
with zipfile.ZipFile(self.file_name, 'r') as zip_file:
zip_file.extractall(output_path)
return True
except:
return False
def create_zip_file(self, files, output_file_name):
"""
Compress the specified file list into a zip file and place it in the specified path
:param files:list of string, List of files to compress
:param output_file_name: string, Specified output path
:return:True or False, representing whether the compression operation was successful
>>> zfp = ZipFileProcessor("aaa.zip")
>>> zfp.create_zip_file(["bbb.txt", "ccc,txt", "ddd.txt"], "output/bcd")
"""
try:
with zipfile.ZipFile(output_file_name, 'w') as zip_file:
for file in files:
zip_file.write(file)
return True
except:
return False | import zipfile
class ZipFileProcessor:
"""
This is a compressed file processing class that provides the ability to read and decompress compressed files
"""
def __init__(self, file_name):
"""
Initialize file name
:param file_name:string
"""
self.file_name = file_name
def read_zip_file(self):
"""
Get open file object
:return:If successful, returns the open file object; otherwise, returns None
>>> zfp = ZipFileProcessor("aaa.zip")
>>> file = zfp.read_zip_file()
"""
def extract_all(self, output_path):
"""
Extract all zip files and place them in the specified path
:param output_path: string, The location of the extracted file
:return: True or False, representing whether the extraction operation was successful
>>> zfp = ZipFileProcessor("aaa.zip")
>>> zfp.extract_all("result/aaa")
"""
def create_zip_file(self, files, output_file_name):
"""
Compress the specified file list into a zip file and place it in the specified path
:param files:list of string, List of files to compress
:param output_file_name: string, Specified output path
:return:True or False, representing whether the compression operation was successful
>>> zfp = ZipFileProcessor("aaa.zip")
>>> zfp.create_zip_file(["bbb.txt", "ccc,txt", "ddd.txt"], "output/bcd")
""" | def extract_file(self, file_name, output_path):
try:
with zipfile.ZipFile(self.file_name, 'r') as zip_file:
zip_file.extract(file_name, output_path)
return True
except:
return False | Extract the file with the specified name from the zip file and place it in the specified path |
ClassEval_99_sum | import zipfile
class ZipFileProcessor:
"""
This is a compressed file processing class that provides the ability to read and decompress compressed files
"""
def __init__(self, file_name):
self.file_name = file_name
def read_zip_file(self):
"""
Get open file object
:return:If successful, returns the open file object; otherwise, returns None
>>> zfp = ZipFileProcessor("aaa.zip")
>>> file = zfp.read_zip_file()
"""
try:
zip_file = zipfile.ZipFile(self.file_name, 'r')
return zip_file
except:
return None
def extract_all(self, output_path):
"""
Extract all zip files and place them in the specified path
:param output_path: string, The location of the extracted file
:return: True or False, representing whether the extraction operation was successful
>>> zfp = ZipFileProcessor("aaa.zip")
>>> zfp.extract_all("result/aaa")
"""
try:
with zipfile.ZipFile(self.file_name, 'r') as zip_file:
zip_file.extractall(output_path)
return True
except:
return False
def extract_file(self, file_name, output_path):
"""
Extract the file with the specified name from the zip file and place it in the specified path
:param file_name:string, The name of the file to be uncompressed
:param output_path:string, The location of the extracted file
:return: True or False, representing whether the extraction operation was successful
>>> zfp = ZipFileProcessor("aaa.zip")
>>> zfp.extract_file("bbb.txt", "result/aaa")
"""
try:
with zipfile.ZipFile(self.file_name, 'r') as zip_file:
zip_file.extract(file_name, output_path)
return True
except:
return False
def create_zip_file(self, files, output_file_name):
try:
with zipfile.ZipFile(output_file_name, 'w') as zip_file:
for file in files:
zip_file.write(file)
return True
except:
return False | import zipfile
class ZipFileProcessor:
"""
This is a compressed file processing class that provides the ability to read and decompress compressed files
"""
def __init__(self, file_name):
"""
Initialize file name
:param file_name:string
"""
self.file_name = file_name
def read_zip_file(self):
"""
Get open file object
:return:If successful, returns the open file object; otherwise, returns None
>>> zfp = ZipFileProcessor("aaa.zip")
>>> file = zfp.read_zip_file()
"""
def extract_all(self, output_path):
"""
Extract all zip files and place them in the specified path
:param output_path: string, The location of the extracted file
:return: True or False, representing whether the extraction operation was successful
>>> zfp = ZipFileProcessor("aaa.zip")
>>> zfp.extract_all("result/aaa")
"""
def extract_file(self, file_name, output_path):
"""
Extract the file with the specified name from the zip file and place it in the specified path
:param file_name:string, The name of the file to be uncompressed
:param output_path:string, The location of the extracted file
:return: True or False, representing whether the extraction operation was successful
>>> zfp = ZipFileProcessor("aaa.zip")
>>> zfp.extract_file("bbb.txt", "result/aaa")
"""
def create_zip_file(self, files, output_file_name):
"""
Compress the specified file list into a zip file and place it in the specified path
:param files:list of string, List of files to compress
:param output_file_name: string, Specified output path
:return:True or False, representing whether the compression operation was successful
>>> zfp = ZipFileProcessor("aaa.zip")
>>> zfp.create_zip_file(["bbb.txt", "ccc,txt", "ddd.txt"], "output/bcd")
""" | def create_zip_file(self, files, output_file_name):
try:
with zipfile.ZipFile(output_file_name, 'w') as zip_file:
for file in files:
zip_file.write(file)
return True
except:
return False | Compress the specified file list into a zip file and place it in the specified path |