當前位置: 首頁>>代碼示例>>Python>>正文


Python os.tempnam方法代碼示例

本文整理匯總了Python中os.tempnam方法的典型用法代碼示例。如果您正苦於以下問題:Python os.tempnam方法的具體用法?Python os.tempnam怎麽用?Python os.tempnam使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在os的用法示例。


在下文中一共展示了os.tempnam方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: plist_save

# 需要導入模塊: import os [as 別名]
# 或者: from os import tempnam [as 別名]
def plist_save(filename, data, binary = False):
	import plistlib
	if not binary:
		plistlib.writePlist(data, filename)
		return 0
	import warnings
	warnings.filterwarnings("ignore")
	tmpname = os.tempnam(None, 'plist.')
	plistlib.writePlist(data, tmpname)
	plutil('-convert', 'binary1', '-o', filename, tmpname)
	os.remove(tmpname)
	return 0


#----------------------------------------------------------------------
# testing case
#---------------------------------------------------------------------- 
開發者ID:skywind3000,項目名稱:collection,代碼行數:19,代碼來源:shell.py

示例2: singular

# 需要導入模塊: import os [as 別名]
# 或者: from os import tempnam [as 別名]
def singular(cmd, isAll=False, debug=False):
  assert check("Singular")
  if isinstance(cmd, str):
    cmd = [cmd]
  s = ";\n".join(cmd) + ";"
  if debug:
    print("[+] Throughout to Singular Commands: {!r}".format(cmd))
  tmpname = os.tempnam()
  open(tmpname, "w").write(s)
  p = Popen(["Singular", "-bq", tmpname], stdin=PIPE, stdout=PIPE)
  d, _ = p.communicate()
  os.remove(tmpname)
  if isAll:
    return d.split("\n")[:-1]
  else:
    return d.split("\n")[:-1][-1] 
開發者ID:scryptos,項目名稱:scryptoslib,代碼行數:18,代碼來源:singular.py

示例3: _get_preview_filename

# 需要導入模塊: import os [as 別名]
# 或者: from os import tempnam [as 別名]
def _get_preview_filename(self):
        import warnings
        warnings.filterwarnings("ignore", "tempnam", RuntimeWarning, "application")
        if compat.PYTHON2:
            out_name = os.tempnam(None, 'wxg') + '.py'
        else:
            # create a temporary file at either the output path or the project path
            error = None
            if not self.filename:
                error = "Save project first; a temporary file will be created in the same directory."
            else:
                dirname, basename = os.path.split(self.filename)
                basename, extension = os.path.splitext(basename)
                if not os.path.exists(dirname):
                    error = "Directory '%s' not found"%dirname
                elif not os.path.isdir(dirname):
                    error = "'%s' is not a directory"%dirname
            if error:
                misc.error_message(error)
                return None
            while True:
                out_name = os.path.join(dirname, "_%s_%d.py"%(basename,random.randrange(10**8, 10**9)))
                if not os.path.exists(out_name): break
        return out_name 
開發者ID:wxGlade,項目名稱:wxGlade,代碼行數:26,代碼來源:application.py

示例4: get_consensus_through_pbdagcon

# 需要導入模塊: import os [as 別名]
# 或者: from os import tempnam [as 別名]
def get_consensus_through_pbdagcon(seq1, weight1, seq2, weight2):
    fname = os.tempnam("/tmp") + '.fasta'
    with open(fname, 'w') as f:
        for i in range(min(10, weight1)): # max cutoff at 10
            f.write(">test1_{0}\n{1}\n".format(i, seq1))
        for i in range(min(10, weight2)): # max cutoff at 10
            f.write(">test2_{0}\n{1}\n".format(i, seq2))

    cmd = "ice_pbdagcon.py --maxScore 10 {0} {0}.g_con g_con".format(fname)
    if subprocess.check_call(cmd, shell=True) == -1:
        raise Exception("Trouble running cmd: ").with_traceback(cmd)

    gcon_filename = fname + '.g_con.fasta'
    gref_filename = fname + '.g_con_ref.fasta'
    if os.path.exists(gcon_filename) and os.stat(gcon_filename).st_size > 0:
        return str(SeqIO.parse(open(gcon_filename), 'fasta').next().seq)
    elif os.path.exists(gref_filename):
        return str(SeqIO.parse(open(gref_filename), 'fasta').next().seq)
    else:
        raise Exception("Could not get results from running cmd:").with_traceback(cmd) 
開發者ID:Magdoll,項目名稱:Cogent,代碼行數:22,代碼來源:splice_align.py

示例5: tempnam_no_warning

# 需要導入模塊: import os [as 別名]
# 或者: from os import tempnam [as 別名]
def tempnam_no_warning(*args):
    """
    An os.tempnam with the warning turned off, because sometimes
    you just need to use this and don't care about the stupid
    security warning.
    """
    return os.tempnam(*args) 
開發者ID:linuxscout,項目名稱:mishkal,代碼行數:9,代碼來源:fixture.py

示例6: test_tempnam

# 需要導入模塊: import os [as 別名]
# 或者: from os import tempnam [as 別名]
def test_tempnam(self):
        with warnings.catch_warnings():
            warnings.filterwarnings("ignore", "tempnam", RuntimeWarning,
                                    r"test_os$")
            warnings.filterwarnings("ignore", "tempnam", DeprecationWarning)
            self.check_tempfile(os.tempnam())

            name = os.tempnam(test_support.TESTFN)
            self.check_tempfile(name)

            name = os.tempnam(test_support.TESTFN, "pfx")
            self.assertTrue(os.path.basename(name)[:3] == "pfx")
            self.check_tempfile(name) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:15,代碼來源:test_os.py

示例7: test_load_negative

# 需要導入模塊: import os [as 別名]
# 或者: from os import tempnam [as 別名]
def test_load_negative(self):
        if cPickle.__name__ == "cPickle":   # pickle vs. cPickle report different exceptions, even on Cpy
            filename = os.tempnam()
            for temp in ['\x02', "No"]:
                self.write_to_file(filename, content=temp)
                f = open(filename)
                self.assertRaises(cPickle.UnpicklingError, cPickle.load, f)
                f.close() 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:10,代碼來源:test_cPickle.py

示例8: get_temp_file

# 需要導入模塊: import os [as 別名]
# 或者: from os import tempnam [as 別名]
def get_temp_file(keep=False, autoext=""):
    f = os.tempnam("","scapy")
    if not keep:
        conf.temp_files.append(f+autoext)
    return f 
開發者ID:medbenali,項目名稱:CyberScan,代碼行數:7,代碼來源:utils.py

示例9: test_tempnam

# 需要導入模塊: import os [as 別名]
# 或者: from os import tempnam [as 別名]
def test_tempnam(self):
        if not hasattr(os, "tempnam"):
            return
        with warnings.catch_warnings():
            warnings.filterwarnings("ignore", "tempnam", RuntimeWarning,
                                    r"test_os$")
            warnings.filterwarnings("ignore", "tempnam", DeprecationWarning)
            self.check_tempfile(os.tempnam())

            name = os.tempnam(test_support.TESTFN)
            self.check_tempfile(name)

            name = os.tempnam(test_support.TESTFN, "pfx")
            self.assertTrue(os.path.basename(name)[:3] == "pfx")
            self.check_tempfile(name) 
開發者ID:dxwu,項目名稱:BinderFilter,代碼行數:17,代碼來源:test_os.py

示例10: test_tempnam

# 需要導入模塊: import os [as 別名]
# 或者: from os import tempnam [as 別名]
def test_tempnam(self):
        '''Test for `os.tempnam` / `os.tmpnam`.'''
        expect = {
            'SEVERITY': {'UNDEFINED': 0, 'LOW': 0, 'MEDIUM': 6, 'HIGH': 0},
            'CONFIDENCE': {'UNDEFINED': 0, 'LOW': 0, 'MEDIUM': 0, 'HIGH': 6}
        }
        self.check_example('tempnam.py', expect) 
開發者ID:PyCQA,項目名稱:bandit,代碼行數:9,代碼來源:test_functional.py

示例11: test_load_negative

# 需要導入模塊: import os [as 別名]
# 或者: from os import tempnam [as 別名]
def test_load_negative(self):
        if cPickle.__name__ == "_pickle":   # pickle vs. cPickle report different exceptions, even on Cpy
            filename = os.tempnam()
            for temp in ['\x02', "No"]:
                self.write_to_file(filename, content=temp)
                f = open(filename)
                self.assertRaises(cPickle.UnpicklingError, cPickle.load, f)
                f.close() 
開發者ID:IronLanguages,項目名稱:ironpython3,代碼行數:10,代碼來源:test_cPickle.py

示例12: plist_load

# 需要導入模塊: import os [as 別名]
# 或者: from os import tempnam [as 別名]
def plist_load(filename):
	import plistlib
	fp = open(filename, 'rb')
	content = fp.read(8)
	fp.close()
	if content == 'bplist00':
		import warnings
		warnings.filterwarnings("ignore")
		tmpname = os.tempnam(None, 'plist.')
		plutil('-convert', 'xml1', '-o', tmpname, filename)
		data = plistlib.readPlist(tmpname)
		os.remove(tmpname)
		return data
	data = plistlib.readPlist(filename)
	return data 
開發者ID:skywind3000,項目名稱:collection,代碼行數:17,代碼來源:shell.py

示例13: setUp

# 需要導入模塊: import os [as 別名]
# 或者: from os import tempnam [as 別名]
def setUp(self):
        super(LdbTestCase, self).setUp()
        self.filename = os.tempnam()
        self.ldb = samba.Ldb(self.filename) 
開發者ID:byt3bl33d3r,項目名稱:pth-toolkit,代碼行數:6,代碼來源:__init__.py

示例14: test_tempnam

# 需要導入模塊: import os [as 別名]
# 或者: from os import tempnam [as 別名]
def test_tempnam(self):
        if not hasattr(os, "tempnam"):
            return
        warnings.filterwarnings("ignore", "tempnam", RuntimeWarning,
                                r"test_os$")
        self.check_tempfile(os.tempnam())

        name = os.tempnam(test_support.TESTFN)
        self.check_tempfile(name)

        name = os.tempnam(test_support.TESTFN, "pfx")
        self.assert_(os.path.basename(name)[:3] == "pfx")
        self.check_tempfile(name) 
開發者ID:ofermend,項目名稱:medicare-demo,代碼行數:15,代碼來源:test_os.py

示例15: format_string

# 需要導入模塊: import os [as 別名]
# 或者: from os import tempnam [as 別名]
def format_string(fp, str):
    str = re.sub("<<([^>]+)>>", "See also pychart.\\1", str)

    str2 = ""
    in_example = 0
    for l in str.split("\n"):
        if re.match("@example", l):
            in_example = 1
        if re.match("@end example", l):
            in_example = 0
        if in_example:
            str2 += l
        else:
            l = re.sub("^[ \t]*", "", l)
            str2 += l
        str2 += "\n"
    fname = os.tempnam()
    out_fp = open(fname, "w")
    out_fp.write(str2)
    out_fp.close()

    in_fp = os.popen("makeinfo --fill-column=64 --no-headers " + fname, "r")
    for l in in_fp.readlines():
        fp.write(" " * indent)
        fp.write(l)
    in_fp.close()
    os.remove(fname) 
開發者ID:Scemoon,項目名稱:lpts,代碼行數:29,代碼來源:generate_docs.py


注:本文中的os.tempnam方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。