Пример #1
0
 def test_sane_template(self):
     p = tempfile.gettempprefix()
     self.assertIsInstance(p, str)
     self.assertGreater(len(p), 0)
     pb = tempfile.gettempprefixb()
     self.assertIsInstance(pb, bytes)
     self.assertGreater(len(pb), 0)
Пример #2
0
    def test_gettempprefix(self):
        ctx = self.TM.new_context()
        pre = ctx.gettempprefix()
        self.assertIsInstance(pre, str)
        self.assertEqual(pre, tempfile.gettempprefix())

        preb = ctx.gettempprefixb()
        self.assertIsInstance(preb, bytes)
        self.assertEqual(preb, tempfile.gettempprefixb())
Пример #3
0
    def test_sane_template(self):
        # gettempprefix returns a nonempty prefix string
        p = tempfile.gettempprefix()

        self.assertIsInstance(p, str)
        self.assertGreater(len(p), 0)

        pb = tempfile.gettempprefixb()

        self.assertIsInstance(pb, bytes)
        self.assertGreater(len(pb), 0)
Пример #4
0
    def test_sane_template(self):
        # gettempprefix returns a nonempty prefix string
        p = tempfile.gettempprefix()

        self.assertIsInstance(p, str)
        self.assertGreater(len(p), 0)

        pb = tempfile.gettempprefixb()

        self.assertIsInstance(pb, bytes)
        self.assertGreater(len(pb), 0)
Пример #5
0
 def gettempprefixb(self):
     return tempfile.gettempprefixb()
Пример #6
0
def tmp11():
    print(tempfile.gettempdir())
    print(tempfile.gettempprefix())
    print(tempfile.gettempdirb())
    print(tempfile.gettempprefixb())
    print(os.sep)
Пример #7
0
 def update_event(self, inp=-1):
     self.set_output_val(0, tempfile.gettempprefixb())
Пример #8
0
    def gettempprefixb(self):
        """Same as :meth:`gettempprefix()`, but the return value is ``bytes``

        """
        return tempfile.gettempprefixb()
Пример #9
0
	增加的max_size参数默认为0,当内存中需要写入数据大小超过max_size后或文件的fileno()方法被调用时,将内容写入硬盘,此时操作与TemporaryFile一致'''
# tempfile.SpooledTemporaryFile(max_size=0, mode='w+b', buffering=None, encoding=None, newline=None, suffix=None, prefix=None, dir=None)
'''生成临时目录'''
# tempfile.TemporaryDirectory(suffix=None, prefix=None, dir=None)

import tempfile

fp = tempfile.TemporaryFile()
print(
    fp.name)  # C:\Users\dxj728\AppData\Local\Temp\tmppzl2lqxk    \\ 返回临时文件路径名

print(tempfile.gettempdir()
      )  # C:\Users\dxj728\AppData\Local\Temp                \\ 获取系统的临时目录
print(tempfile.gettempdirb()
      )  # b'C:\\Users\\dxj728\\AppData\\Local\\Temp'        \\ 与上相同,只是返回字节串
print(tempfile.gettempprefix()
      )  # tmp                                               \\ 返回用于生成临时文件的前缀名
print(tempfile.gettempprefixb()
      )  # b'tmp'                                            \\ 与上相同,只是返回字节串

fp.write('hello'.encode('utf-8'))
fp.write('world'.encode('utf-8'))

fp.seek(0)  # 文件指针移到开始处,准备读取文件
print(fp.read().decode('utf-8'))

fp.close()  # 关闭临时文件,该文件会被自动删除

with tempfile.TemporaryDirectory() as fd:  # 使用with语句创建临时目录
    print(fd)  # C:\Users\dxj728\AppData\Local\Temp\tmpfv9k_b8m    \\ 返回临时目录
Пример #10
0
# -*- encoding: utf-8 -*-
import tempfile

print("Dir temporal del sistema", tempfile.gettempdir())
print("Dir temporal (en bytes)", tempfile.gettempdirb())  # Python +3.5

print("Prefijo:", tempfile.gettempprefix())
print("Prefijo (en bytes)", tempfile.gettempprefixb())  # Python +3.5

#tempfile.tempdir = '/home/usuario/temp'
print("Directorio temporal", tempfile.gettempdir())
print("Directorio temporal", tempfile.tempdir)