本文整理汇总了Python中zipfile.PyZipFile.open方法的典型用法代码示例。如果您正苦于以下问题:Python PyZipFile.open方法的具体用法?Python PyZipFile.open怎么用?Python PyZipFile.open使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类zipfile.PyZipFile
的用法示例。
在下文中一共展示了PyZipFile.open方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: GenerateMission
# 需要导入模块: from zipfile import PyZipFile [as 别名]
# 或者: from zipfile.PyZipFile import open [as 别名]
def GenerateMission(filename):
# Create XML parser
parser = make_parser()
generator = MissionGenerator()
parser.setContentHandler(generator)
# Parse KMZ file
kmz = PyZipFile(filename, 'r')
kml = kmz.open('doc.kml', 'r')
parser.parse(kml)
kmz.close()
# Arrange the XML items into useful variables
items = {}
items['base_location'] = ParseCoordinates(generator.mapping, 'Base')
items['landing_site'] = ParseCoordinates(generator.mapping, 'Fake reported location')
items['path'] = ParseCoordinates(generator.mapping, 'Sample Nominal Path')
items['return_path']= items['path'].reverse()
items['base_geofence'] = GenerateGeofences(ParseCoordinates(generator.mapping, 'Base geofence'))
items['landing_site_geofence'] = GenerateGeofences(ParseCoordinates(generator.mapping, 'Sample remote landing site'))
items['mission_geofence'] = GenerateGeofences(ParseCoordinates(generator.mapping, 'Sample full geofence'))
return items
示例2: get_module_meta_path
# 需要导入模块: from zipfile import PyZipFile [as 别名]
# 或者: from zipfile.PyZipFile import open [as 别名]
def get_module_meta_path(module_description):
"""Returns the finder to be appended to sys.meta_path
module_description is a tuple of 2 elements:
format: either 'zip', 'tar', 'tar:gz', 'tar:bz' or a string to be used as module name
content: a base64 encoded string of a zip archive, a tar(gz/bz2) archive or a plain python module
"""
raw_format = module_description[0].split(':')
if raw_format[0] in ('zip', 'tar'):
f = BytesIO()
f.write(decodestring(module_description[1]))
f.seek(0)
if raw_format[0] == 'zip':
zipf = PyZipFile(f)
module_dict = dict((splitext(z.filename)[0].replace('/', '.'), zipf.open(z.filename).read()) for z in zipf.infolist() if splitext(z.filename)[1] == ".py")
elif raw_format[0] == 'tar':
compression = raw_format[1] if len(raw_format) > 1 else ''
tarf = taropen(fileobj=f, mode="r:" + compression)
module_dict = dict((splitext(t.name)[0].replace('/', '.'), tarf.extractfile(t.name).read()) for t in tarf.getmembers() if splitext(t.name)[1] == ".py")
else:
module_dict = {module_description[0]: decodestring(module_description[1])}
return Finder(module_dict)