当前位置: 首页>>代码示例>>Python>>正文


Python TemporaryFile.writelines方法代码示例

本文整理汇总了Python中tempfile.TemporaryFile.writelines方法的典型用法代码示例。如果您正苦于以下问题:Python TemporaryFile.writelines方法的具体用法?Python TemporaryFile.writelines怎么用?Python TemporaryFile.writelines使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在tempfile.TemporaryFile的用法示例。


在下文中一共展示了TemporaryFile.writelines方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: exportFile

# 需要导入模块: from tempfile import TemporaryFile [as 别名]
# 或者: from tempfile.TemporaryFile import writelines [as 别名]
 def exportFile(self, oid, f=None):
     if f is None:
         f = TemporaryFile()
     elif isinstance(f, str):
         f = open(f,'w+b')
     f.write('ZEXP')
     oids = [oid]
     done_oids = {}
     done=done_oids.has_key
     load=self._storage.load
     while oids:
         oid = oids.pop(0)
         if oid in done_oids:
             continue
         done_oids[oid] = True
         try:
             p, serial = load(oid, self._version)
         except:
             logger.debug("broken reference for oid %s", repr(oid),
                          exc_info=True)
         else:
             referencesf(p, oids)
             f.writelines([oid, p64(len(p)), p])
     f.write(export_end_marker)
     return f
开发者ID:wpjunior,项目名称:proled,代码行数:27,代码来源:ExportImport.py

示例2: addValues

# 需要导入模块: from tempfile import TemporaryFile [as 别名]
# 或者: from tempfile.TemporaryFile import writelines [as 别名]
    def addValues(self, values, experiment):
        if len(self.variables) == len(values):
            readyProtocol = self.info
            newProtocol = []
            for i in range(0, len(readyProtocol)):
                mystring = readyProtocol[i]
                newProtocol.append(mystring)
                for v in range(0, len(values)):
                    newProtocol[i] = newProtocol[i].replace(self.variables[v], values[v])
            from tempfile import TemporaryFile

            protocolFile = TemporaryFile(mode='r+')
            protocolFile.writelines(newProtocol)
            protocolFile.seek(0)
            line = protocolFile.readline()
            if experiment.platform != 'human':
                experiment.addComment('------ BEGIN PROTOCOL ' + self.name + ', variables: ' + ' '.join(self.variables) + '; values: ' + ' '.join(values) + ' ------')
            else:
                experiment.addComment('$')
            while line != '':
                splitline = line.split()
                LineToList(splitline, protocolFile, experiment)
                line = protocolFile.readline()
            if experiment.platform != 'human':
                experiment.addComment('------ END PROTOCOL ' + self.name + ' ------')
            else:
                experiment.addComment('$')
开发者ID:JBEI,项目名称:prpr,代码行数:29,代码来源:prparser.py

示例3: decompressMessage

# 需要导入模块: from tempfile import TemporaryFile [as 别名]
# 或者: from tempfile.TemporaryFile import writelines [as 别名]
 def decompressMessage(self, src):
     height = int(src[0])
     width = int(src[1])
     tmp = TemporaryFile()
     tmp.writelines(src[2:])
     tmp.seek(0)
     npz = np.load(tmp)
     body = npz['img']
     ret = np.ndarray((height, width), dtype=np.uint8)
     for i in range(height*width):
         if body[i]:
             ret[i/width][i%width] = 255
开发者ID:furushchev,项目名称:image_shrink,代码行数:14,代码来源:image_shrink_client.py

示例4: callback

# 需要导入模块: from tempfile import TemporaryFile [as 别名]
# 或者: from tempfile.TemporaryFile import writelines [as 别名]
    def callback(self, sarray):
        height = sarray[0]
        width = sarray[1]
        tmp = TemporaryFile()
        tmp.writelines(sarray.data)
        tmp.seek(0)

        data = np.load(tmp)
        img = data['img']
        img.shape = (img.shape[0], img.shape[1], 1)
        imgmsg = self.bridge.cv2_to_imgmsg(img)
        imgmsg.encoding = 'mono8'
        self.pub.publish(imgmsg)
开发者ID:furushchev,项目名称:image_shrink,代码行数:15,代码来源:image_shrink_client.py

示例5: write

# 需要导入模块: from tempfile import TemporaryFile [as 别名]
# 或者: from tempfile.TemporaryFile import writelines [as 别名]
 def write(self, data):
     if not self._isFile:
         if self._stream.tell() + len(data) > self._smallFileSize:
             # We are about to go over the small file size limit
             # Move all the contents out to a temporary file and continue
             # writing there.
             from tempfile import TemporaryFile
             fstream = TemporaryFile()
             self._stream.seek(0)
             fstream.writelines(self._stream)
             self._stream.close()
             self._stream = fstream
             self._isFile = True
     self._stream.write(data)
开发者ID:fictitious,项目名称:tracperforceplugin,代码行数:16,代码来源:util.py

示例6: plates

# 需要导入模块: from tempfile import TemporaryFile [as 别名]
# 或者: from tempfile.TemporaryFile import writelines [as 别名]
def plates():
    a = request.body.read().decode().split('\n')[2:-2]
    plateFile = TemporaryFile(mode='r+')
    plateFile.writelines(a)
    plateFile.seek(0)
    plateIndexes = {}
    plateNicknames = {}
    experiment = False
    PlateFileParse(plateFile, experiment, plateNicknames, plateIndexes)
    plates = []
    for key in plateIndexes.keys():
        plates.append([key, [plateIndexes[key][0], plateIndexes[key][1]], plateNicknames[key]])
        tojs = json_dumps(plates)
    print(plateNicknames, plateIndexes)
    return tojs
开发者ID:ktemme,项目名称:prpr,代码行数:17,代码来源:ppserver.py

示例7: bulk_insert

# 需要导入模块: from tempfile import TemporaryFile [as 别名]
# 或者: from tempfile.TemporaryFile import writelines [as 别名]
	def bulk_insert(self, rawData, owner='default'):
		"""
		暂不使用
		:param owner:对应settings中的数据库key,默认为default
		:param rawData:原始数据列表,每个元素是一行数据库记录
		:return:提交成功返回True,提交失败返回False
		"""
		try:
			tempf  = TemporaryFile(mode='w+t')
			for row in rawData:
				tempf.writelines([unicode(item)+' ' for item in row])

			tempf.seek(0)
			tempf.close()
			cursor = connections[owner].cursor()
			cursor.execute(self.sql)
			transaction.commit_unless_managed(owner)
		except Exception, e:
			transaction.rollback(owner)
			return False
开发者ID:SKLCC-Python,项目名称:SKLCC_MSZ_YCL,代码行数:22,代码来源:rawSql.py

示例8: testAddMapping

# 需要导入模块: from tempfile import TemporaryFile [as 别名]
# 或者: from tempfile.TemporaryFile import writelines [as 别名]
    def testAddMapping(self):
        mount = (
        "C:/cygwin/bin on /usr/bin type ntfs (binary,auto){LF}"
        "C:/cygwin/lib on /usr/lib type ntfs (binary,auto){LF}"
        "C:/cygwin on / type ntfs (binary,auto){LF}"
        "C: on /cygdrive/c type ntfs (binary,posix=0,user,noumount,auto){LF}"
        "".format(LF="\n")
        );
        f = TemporaryFile(mode='w+');
        f.writelines(mount);
        f.seek(0);
        mtab = f.readlines();
        f.close();

        mapping = {
            '/usr/bin/': "C:/cygwin/bin/",
            '/usr/lib/': "C:/cygwin/lib/",
            '/cygdrive/c/': "C:/",
        };
        self.obj._addMapping(mtab);
        self.assertEqual(self.obj.getMap(), mapping);
        self.assertEqual(self.obj.getMountRoot(), "C:/cygwin/");
开发者ID:MyOwnClone,项目名称:cyg-apt,代码行数:24,代码来源:test_path_mapper.py

示例9: y_or_n

# 需要导入模块: from tempfile import TemporaryFile [as 别名]
# 或者: from tempfile.TemporaryFile import writelines [as 别名]
(save_indexed_png_glob "%s")
(gimp-quit 0)
""" % (pattern, )

import sys
def y_or_n():
	while True:
		response = sys.stdin.readline().strip()
		if response == 'y': return True
		elif response == 'n': return False
		else: print "Please enter 'y' or 'n'"
		
sys.stdout.write("""WARNING: 
  This script will permanently convert (and reduce the quality of)
  all files matching the pattern "%s" in this directory. 
  Please ensure you have backed up the originals. 
  PNGs already indexed will not be affected. 
  Are you sure you wish to proceed? (y/n) """ % (pattern, ))

if y_or_n():
	from subprocess import *
	from tempfile import TemporaryFile
	t = TemporaryFile()
	t.writelines(scm)
	t.seek(0)
	p = Popen("gimp -ib -", shell=True, stdin=t)
	p.communicate() #wait for completion
else:
	print "Conversion aborted."

开发者ID:acli,项目名称:xiphos,代码行数:31,代码来源:index_all_pngs.py


注:本文中的tempfile.TemporaryFile.writelines方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。