本文整理汇总了Python中sys.stderr.write方法的典型用法代码示例。如果您正苦于以下问题:Python stderr.write方法的具体用法?Python stderr.write怎么用?Python stderr.write使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sys.stderr
的用法示例。
在下文中一共展示了stderr.write方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: dump
# 需要导入模块: from sys import stderr [as 别名]
# 或者: from sys.stderr import write [as 别名]
def dump(state):
if not options.DUMP_PRE_ERROR_STATE:
return
stdout.flush()
stderr.flush()
stdout.write(
"\n--- Pre-error state dump: --------------------------------------------\n"
)
try:
state.dump()
finally:
stdout.write(
"----------------------------------------------------------------------\n"
)
stderr.write("\n")
stdout.flush()
stderr.flush()
示例2: __get_request
# 需要导入模块: from sys import stderr [as 别名]
# 或者: from sys.stderr import write [as 别名]
def __get_request(self, url, max_try=3):
stderr.write(url + '\n')
cnt = 0
while cnt < max_try:
try:
req = requests.get(url, headers=self.headers)
except:
cnt += 1
continue
if req.status_code != requests.codes.ok:
break
return req
# Should not reach here if everything is ok.
stderr.write(json.dumps(self.data, ensure_ascii=False, sort_keys=True, indent=4).encode('utf-8', 'replace'))
stderr.write('Error: %s\n' % url)
exit(1)
示例3: __parse_weibo
# 需要导入模块: from sys import stderr [as 别名]
# 或者: from sys.stderr import write [as 别名]
def __parse_weibo(self, soup):
# return all weibo in a page as a list
ret = []
for block in soup.find_all('div', 'c'):
divs = block.find_all('div')
if len(divs) == 1:
text = self.__trim_like(divs[0].get_text())
ret.append(text)
elif len(divs) == 2 or len(divs) == 3:
text = self.__trim_like(divs[0].get_text())
comment = self.__trim_like(divs[-1].get_text())
ret.append(text + comment)
elif len(divs) == 0:
continue
else:
stderr.write('Error: invalid weibo page')
exit(1)
return ret
示例4: integer_list_file
# 需要导入模块: from sys import stderr [as 别名]
# 或者: from sys.stderr import write [as 别名]
def integer_list_file(cls, filename, values, bits = None):
"""
Write a list of integers to a file.
If a file of the same name exists, it's contents are replaced.
See L{HexInput.integer_list_file} for a description of the file format.
@type filename: str
@param filename: Name of the file to write.
@type values: list( int )
@param values: List of integers to write to the file.
@type bits: int
@param bits:
(Optional) Number of bits of the target architecture.
The default is platform dependent. See: L{HexOutput.integer_size}
"""
fd = open(filename, 'w')
for integer in values:
print >> fd, cls.integer(integer, bits)
fd.close()
示例5: string_list_file
# 需要导入模块: from sys import stderr [as 别名]
# 或者: from sys.stderr import write [as 别名]
def string_list_file(cls, filename, values):
"""
Write a list of strings to a file.
If a file of the same name exists, it's contents are replaced.
See L{HexInput.string_list_file} for a description of the file format.
@type filename: str
@param filename: Name of the file to write.
@type values: list( int )
@param values: List of strings to write to the file.
"""
fd = open(filename, 'w')
for string in values:
print >> fd, string
fd.close()
示例6: __logfile_error
# 需要导入模块: from sys import stderr [as 别名]
# 或者: from sys.stderr import write [as 别名]
def __logfile_error(self, e):
"""
Shows an error message to standard error
if the log file can't be written to.
Used internally.
@type e: Exception
@param e: Exception raised when trying to write to the log file.
"""
from sys import stderr
msg = "Warning, error writing log file %s: %s\n"
msg = msg % (self.logfile, str(e))
stderr.write(DebugLog.log_text(msg))
self.logfile = None
self.fd = None
示例7: getnode
# 需要导入模块: from sys import stderr [as 别名]
# 或者: from sys.stderr import write [as 别名]
def getnode(self):
if self.xnode == None:
x_node_ptr = unpacktype(self.smem, self.template['v_data'], INT)
if self.tag == None:
self.tag = unpacktype(self.smem, self.template['v_tag'], SHT)
if self.tag == 16: # VT_HFS
self.xnode = Cnode(x_node_ptr)
elif self.tag == 18: # VT_DEVFS
self.xnode = Devnode(x_node_ptr)
else:
if self.tag < len(Vnode.VNODE_TAG):
s_tag = Vnode.VNODE_TAG[self.tag]
else:
s_tag = str(self.tag)
stderr.write("WARNING Vnode.getnode(): unsupported FS tag %s, returning %d.\n" % (s_tag, ECODE['node']))
return ECODE['node']
return self.xnode.getnode()
示例8: getdev
# 需要导入模块: from sys import stderr [as 别名]
# 或者: from sys.stderr import write [as 别名]
def getdev(self):
if self.tag == None:
self.tag = unpacktype(self.smem, self.template['v_tag'], SHT)
if self.tag == 18: # CHR
vu_specinfo = unpacktype(self.smem, self.template['v_un'], INT)
# this pointer is invalid for /dev (special case DIR using VT_DEVFS)
if not (vu_specinfo == 0) and Struct.mem.is_valid_address(vu_specinfo):
specinfo = Specinfo(vu_specinfo)
return specinfo.getdev()
# default return for REG/DIR/LINK
if self.mount == None:
mount_ptr = unpacktype(self.smem, self.template['v_mount'], INT)
if mount_ptr == 0 or not (Struct.mem.is_valid_address(mount_ptr)):
stderr.write("WARNING Vnode.getdev(): v_mount pointer invalid, returning %d.\n" % ECODE['device'])
return ECODE['device']
self.mount = Mount(mount_ptr)
return self.mount.getdev()
示例9: SaveToFile
# 需要导入模块: from sys import stderr [as 别名]
# 或者: from sys.stderr import write [as 别名]
def SaveToFile(self, filename, canvas):
if hasattr(getattr(filename, "write",None),'__call__'):
myfile = 0
f = filename
filename = makeFileName(getattr(filename,'name',''))
else :
myfile = 1
filename = makeFileName(filename)
f = open(filename, "wb")
data = self.GetPDFData(canvas)
if isUnicode(data):
data = data.encode('latin1')
f.write(data)
if myfile:
f.close()
import os
if os.name=='mac':
from reportlab.lib.utils import markfilename
markfilename(filename) # do platform specific file junk
if getattr(canvas,'_verbosity',None): print('saved %s' % (filename,))
示例10: evaluate
# 需要导入模块: from sys import stderr [as 别名]
# 或者: from sys.stderr import write [as 别名]
def evaluate(operations, DEBUG=False):
from subprocess import Popen, PIPE
if DEBUG:
print
print operations
print
inp = send(operations)
if DEBUG:
print inp
print
with open('vhe.in', 'w') as f:
f.write(inp)
output, error = Popen(['./vhe'], stdin=PIPE, stdout=PIPE, shell=True).communicate('')
if DEBUG:
print output
print
if error:
from sys import stderr
stderr.write(error + '\n')
stderr.flush()
return recv(output)
示例11: zipdir
# 需要导入模块: from sys import stderr [as 别名]
# 或者: from sys.stderr import write [as 别名]
def zipdir(archivename, basedir, ignoredirs=None):
'''Zip directory, from J.F. Sebastian http://stackoverflow.com/'''
assert os.path.isdir(basedir)
if not ignoredirs:
ignoredirs = []
with closing(ZipFile(archivename, "w", ZIP_DEFLATED)) as z:
for root, dirs, files in os.walk(basedir):
for folder in copy.copy(dirs):
abspath = os.path.abspath(os.path.join(root, folder))
if abspath in ignoredirs:
dirs.remove(folder)
# NOTE: ignore empty directories
for fn in files:
if fn[-4:]!='.zip':
absfn = os.path.join(root, fn)
zfn = absfn[len(basedir)+len(os.sep):] # XXX: relative path
z.write(absfn, zfn)
# ================ Inventory input data and create data structure =================
示例12: printexpr
# 需要导入模块: from sys import stderr [as 别名]
# 或者: from sys.stderr import write [as 别名]
def printexpr(expr_string):
""" printexpr(expr) -
print the value of the expression, along with linenumber and filename.
"""
stack = extract_stack ( )[-2:][0]
actualCall = stack[3]
left = string.find ( actualCall, '(' )
right = string.rfind ( actualCall, ')' )
caller_globals,caller_locals = _caller_symbols()
expr = eval(expr_string,caller_globals,caller_locals)
varType = type( expr )
stderr.write("%s:%d> %s == %s (%s)\n" % (
stack[0], stack[1],
string.strip( actualCall[left+1:right] )[1:-1],
repr(expr), str(varType)[7:-2]))
示例13: tempfile
# 需要导入模块: from sys import stderr [as 别名]
# 或者: from sys.stderr import write [as 别名]
def tempfile(self,calcMD5=False,calcSHA1=False,calcSHA256=False):
"""Return the contents of imagefile in a named temporary file. If
calcMD5, calcSHA1, or calcSHA256 are set TRUE, then the object
returned has a hashlib object as self.md5 or self.sha1 with the
requested hash."""
import tempfile
tf = tempfile.NamedTemporaryFile()
if calcMD5: tf.md5 = hashlib.md5()
if calcSHA1: tf.sha1 = hashlib.sha1()
if calcSHA256: tf.sha256 = hashlib.sha256()
for run in self.byte_runs():
self.imagefile.seek(run.img_offset)
count = run.len
while count>0:
xfer_len = min(count,1024*1024) # transfer up to a megabyte at a time
buf = self.imagefile.read(xfer_len)
if len(buf)==0: break
tf.write(buf)
if calcMD5: tf.md5.update(buf)
if calcSHA1: tf.sha1.update(buf)
if calcSHA256: tf.sha256.update(buf)
count -= xfer_len
tf.flush()
return tf
示例14: __call__
# 需要导入模块: from sys import stderr [as 别名]
# 或者: from sys.stderr import write [as 别名]
def __call__(self):
with self._lock:
if self._nbytes >= 0:
self._data[self._hpath] = self._nbytes
else:
stderr.write('%s\n' % (sum(self._data.values()), ))
示例15: put_file_csv
# 需要导入模块: from sys import stderr [as 别名]
# 或者: from sys.stderr import write [as 别名]
def put_file_csv(hdfs_file_content,hdfs_path,hdfs_file_name,append_file=False,overwrite_file=False, client=None):
if not client:
client = get_client()
try:
hdfs_full_name = "{0}/{1}".format(hdfs_path,hdfs_file_name)
with client.write(hdfs_full_name,append=append_file,overwrite=overwrite_file) as writer:
for item in hdfs_file_content:
data = ','.join(str(d) for d in item)
writer.write("{0}\n".format(data))
return True
except HdfsError:
return False