本文整理汇总了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
#----------------------------------------------------------------------
示例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]
示例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
示例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)
示例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)
示例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)
示例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()
示例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
示例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)
示例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)
示例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()
示例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
示例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)
示例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)
示例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)