Python string 模块,joinfields() 实例源码
我们从Python开源项目中,提取了以下22个代码示例,用于说明如何使用string.joinfields()。
def sendportcmd(s, f, port):
hostname = gethostname()
hostaddr = gethostbyname(hostname)
hbytes = string.splitfields(hostaddr, '.')
pbytes = [repr(port//256), repr(port%256)]
bytes = hbytes + pbytes
cmd = 'PORT ' + string.joinfields(bytes, ',')
s.send(cmd + '\r\n')
code = getreply(f)
# Process an ftp reply and return the 3-digit reply code (as a string).
# The reply should be a line of text starting with a 3-digit number.
# If the 4th char is '-',it is a multi-line reply and is
# terminate by a line starting with the same 3-digit number.
# Any text while receiving the reply is echoed to the file.
#
def writelines(self, list):
self.write(string.joinfields(list, ''))
def flush(self):
print 'flush: %d blocks,%d bytes' % (len(self._buffer), self._filled)
if self._buffer:
import string
self._base.writeframes(string.joinfields(self._buffer, ''))
self._buffer = []
self._filled = 0
def write_map(self, m):
sc = StringCodec()
if m is not None:
sc.write_uint32(len(m))
sc.write(string.joinfields(map(self._write_map_elem, m.keys(), m.values()), ""))
self.write_vbin32(sc.encoded)
def text(self, xy, text):
text = string.joinfields(string.splitfields(text, "("), "\\(")
text = string.joinfields(string.splitfields(text, ")"), "\\)")
xy = xy + (text,)
self.fp.write("%d %d M (%s) S\n" % xy)
def __str__(self):
"""Return a human-readable representation.
>>> str(N['dog'][0].synset)
'{noun: dog,domestic dog,Canis familiaris}'
"""
return "{" + self.pos + ": " + string.joinfields(map(lambda sense:sense.form, self.getSenses()), ",") + "}"
def __str__(self):
"""Return a human-readable representation.
>>> str(N['dog'][0].synset)
'{noun: dog,") + "}"
def more(self):
if not self.file_list:
return ''
else:
# do a few at a time
bunch = self.file_list[:50]
if self.long:
bunch = map(self.longify, bunch)
self.file_list = self.file_list[50:]
return string.joinfields(bunch, '\r\n') + '\r\n'
def hex_digest(s):
m = md5()
m.update(s)
return string.joinfields(
map(lambda x: hex(ord(x))[2:], map(None, m.digest())),
'',
)
def __str__(self):
"""Return a human-readable representation.
>>> str(N['dog'][0].synset)
'{noun: dog,") + "}"
def __str__(self):
"""Return a human-readable representation.
>>> str(N['dog'][0].synset)
'{noun: dog,") + "}"
def text(self,)
self.fp.write("%d %d M (%s) S\n" % xy)
def __str__(self):
"""Return a human-readable representation.
>>> str(N['dog'][0].synset)
'{noun: dog,") + "}"
def __str__(self):
"""Return a human-readable representation.
>>> str(N['dog'][0].synset)
'{noun: dog,") + "}"
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。