本文整理汇总了Python中string.zfill方法的典型用法代码示例。如果您正苦于以下问题:Python string.zfill方法的具体用法?Python string.zfill怎么用?Python string.zfill使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类string
的用法示例。
在下文中一共展示了string.zfill方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _generate_key
# 需要导入模块: import string [as 别名]
# 或者: from string import zfill [as 别名]
def _generate_key(self, key_type, cache_key):
x_fill = zfill(cache_key.coord.column, 9)
y_fill = zfill(cache_key.coord.row, 9)
return os.path.join(
self.prefix,
str(cache_key.tile_size),
cache_key.layers,
zfill(cache_key.coord.zoom, 2),
x_fill[0:3],
x_fill[3:6],
x_fill[6:9],
y_fill[0:3],
y_fill[3:6],
'{}.{}.{}'.format(y_fill[6:9], cache_key.fmt.extension, key_type),
)
示例2: ttList
# 需要导入模块: import string [as 别名]
# 或者: from string import zfill [as 别名]
def ttList(input, output, options):
import string
ttf = TTFont(input, fontNumber=options.fontNumber)
reader = ttf.reader
tags = reader.keys()
tags.sort()
print 'Listing table info for "%s":' % input
format = " %4s %10s %7s %7s"
print format % ("tag ", " checksum", " length", " offset")
print format % ("----", "----------", "-------", "-------")
for tag in tags:
entry = reader.tables[tag]
checkSum = long(entry.checkSum)
if checkSum < 0:
checkSum = checkSum + 0x100000000L
checksum = "0x" + string.zfill(hex(checkSum)[2:-1], 8)
print format % (tag, checksum, entry.length, entry.offset)
print
ttf.close()
示例3: parseCharset
# 需要导入模块: import string [as 别名]
# 或者: from string import zfill [as 别名]
def parseCharset(numGlyphs, file, strings, isCID, format):
charset = ['.notdef']
count = 1
if format == 1:
nLeftFunc = readCard8
else:
nLeftFunc = readCard16
while count < numGlyphs:
first = readCard16(file)
nLeft = nLeftFunc(file)
if isCID:
for CID in range(first, first+nLeft+1):
charset.append("cid" + string.zfill(str(CID), 5) )
else:
for SID in range(first, first+nLeft+1):
charset.append(strings[SID])
count = count + nLeft + 1
return charset
示例4: spew_internaldate
# 需要导入模块: import string [as 别名]
# 或者: from string import zfill [as 别名]
def spew_internaldate(self, id, msg, _w=None, _f=None):
if _w is None:
_w = self.transport.write
idate = msg.getInternalDate()
ttup = rfc822.parsedate_tz(idate)
if ttup is None:
log.msg("%d:%r: unpareseable internaldate: %r" % (id, msg, idate))
raise IMAP4Exception("Internal failure generating INTERNALDATE")
odate = time.strftime("%d-%b-%Y %H:%M:%S ", ttup[:9])
if ttup[9] is None:
odate = odate + "+0000"
else:
if ttup[9] >= 0:
sign = "+"
else:
sign = "-"
odate = odate + sign + string.zfill(str(((abs(ttup[9]) / 3600) * 100 + (abs(ttup[9]) % 3600) / 60)), 4)
_w('INTERNALDATE ' + _quote(odate))
示例5: updateTime
# 需要导入模块: import string [as 别名]
# 或者: from string import zfill [as 别名]
def updateTime( self ):
"""Update time display if disc is loaded"""
if self.CD.get_init():
seconds = int( self.CD.get_current()[ 1 ] )
endSeconds = int( self.CD.get_track_length(
self.currentTrack - 1 ) )
# if reached end of current track, play next track
if seconds >= ( endSeconds - 1 ):
self.nextTrack()
else:
minutes = seconds / 60
endMinutes = endSeconds / 60
seconds = seconds - ( minutes * 60 )
endSeconds = endSeconds - ( endMinutes * 60 )
# display time in format mm:ss/mm:ss
trackTime = string.zfill( str( minutes ), 2 ) + \
":" + string.zfill( str( seconds ), 2 )
endTime = string.zfill( str( endMinutes ), 2 ) + \
":" + string.zfill( str( endSeconds ), 2 )
if self.CD.get_paused():
# alternate pause symbol and time in display
if not self.timeLabel.get() == " || ":
self.timeLabel.set( " || " )
else:
self.timeLabel.set( trackTime + "/" + endTime )
else:
self.timeLabel.set( trackTime + "/" + endTime )
# call updateTime method again after 1000ms ( 1 second )
self.after( 1000, self.updateTime )
示例6: getFullName
# 需要导入模块: import string [as 别名]
# 或者: from string import zfill [as 别名]
def getFullName(picture, counter):
return normalize(string.zfill(counter, CONSTANT_FILL) + '_' + picture[2] + '_' + picture[1])
示例7: now
# 需要导入模块: import string [as 别名]
# 或者: from string import zfill [as 别名]
def now():
"""Returns a string containing the current date and time.
This function is used internally by VideoCapture to generate the timestamp
with which a snapshot can optionally be marked.
"""
weekday = ('Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun')
#weekday = ('Mo', 'Di', 'Mi', 'Do', 'Fr', 'Sa', 'So')
#weekday = ('-', '-', '-', '-', '-', '-', '-')
y, m, d, hr, min, sec, wd, jd, dst = time.localtime(time.time())
return '%s:%s:%s %s %s.%s.%s' % (string.zfill(hr, 2), string.zfill(min, 2), string.zfill(sec, 2), weekday[wd], d, m, y)
示例8: increment
# 需要导入模块: import string [as 别名]
# 或者: from string import zfill [as 别名]
def increment(s):
""" look for the last sequence of number(s) in a string and increment """
if numbers.findall(s):
lastoccr_sre = list(numbers.finditer(s))[-1]
lastoccr = lastoccr_sre.group()
lastoccr_incr = str(int(lastoccr) + 1)
if len(lastoccr) > len(lastoccr_incr):
lastoccr_incr = zfill(lastoccr_incr, len(lastoccr))
return s[:lastoccr_sre.start()]+lastoccr_incr+s[lastoccr_sre.end():]
return s
示例9: parseCharset0
# 需要导入模块: import string [as 别名]
# 或者: from string import zfill [as 别名]
def parseCharset0(numGlyphs, file, strings, isCID):
charset = [".notdef"]
if isCID:
for i in range(numGlyphs - 1):
CID = readCard16(file)
charset.append("cid" + string.zfill(str(CID), 5) )
else:
for i in range(numGlyphs - 1):
SID = readCard16(file)
charset.append(strings[SID])
return charset
示例10: hexdigest
# 需要导入模块: import string [as 别名]
# 或者: from string import zfill [as 别名]
def hexdigest(self):
"""Like digest(), but returns a string of hexadecimal digits instead.
"""
return "".join([string.zfill(hex(ord(x))[2:], 2)
for x in tuple(self.digest())])
示例11: WriteRest
# 需要导入模块: import string [as 别名]
# 或者: from string import zfill [as 别名]
def WriteRest(self):
"""Finish the file"""
ws = self.writestr
self._locations[3] = self._fpos
ws("3 0 obj\n")
ws("<<\n")
ws("/Type /Pages\n")
buf = "".join(("/Count ", str(self._pageNo), "\n"))
ws(buf)
buf = "".join(
("/MediaBox [ 0 0 ", str(self._pageWd), " ", str(self._pageHt), " ]\n"))
ws(buf)
ws("/Kids [ ")
for i in range(1, self._pageNo + 1):
buf = "".join((str(self._pageObs[i]), " 0 R "))
ws(buf)
ws("]\n")
ws(">>\n")
ws("endobj\n")
xref = self._fpos
ws("xref\n")
buf = "".join(("0 ", str((self._curobj) + 1), "\n"))
ws(buf)
buf = "".join(("0000000000 65535 f ", str(LINE_END)))
ws(buf)
for i in range(1, self._curobj + 1):
val = self._locations[i]
buf = "".join(
(string.zfill(str(val), 10), " 00000 n ", str(LINE_END)))
ws(buf)
ws("trailer\n")
ws("<<\n")
buf = "".join(("/Size ", str(self._curobj + 1), "\n"))
ws(buf)
ws("/Root 2 0 R\n")
ws("/Info 1 0 R\n")
ws(">>\n")
ws("startxref\n")
buf = "".join((str(xref), "\n"))
ws(buf)
ws("%%EOF\n")