本文整理汇总了Python中string.rjust函数的典型用法代码示例。如果您正苦于以下问题:Python rjust函数的具体用法?Python rjust怎么用?Python rjust使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了rjust函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: show_from_cache
def show_from_cache(self):
cache = inventory.CachedInventory()
if self.args.type == 'instances':
for inst in cache.instances(self.customer):
if self.args.ec2_region != 'all' and self.args.ec2_region != inst['region']:
continue
print inst['_id'], string.rjust(inst['region'], 10), string.rjust(inst['state'], 10)
elif self.args.type == 'volumes':
for vol in cache.volumes(self.customer):
if self.args.ec2_region != 'all' and self.args.ec2_region != vol['region']:
continue
if self.args.instance != None and self.args.instance != vol['instance_id']:
continue
print vol['_id'], vol['instance_id'], string.rjust(vol['region'], 10), string.rjust(vol['status'], 10), string.rjust(vol['device'], 10)
elif self.args.type == 'snapshots':
for snap in cache.snapshots(self.customer): #.limit(10):
if self.args.ec2_region != 'all' and self.args.ec2_region != snap['region']:
continue
if self.args.volume != None and self.args.volume != snap['volume_id']:
continue
print "%s %s %s %s %s" % (
snap['_id'],
snap['volume_id'],
snap['region'],
snap['status'],
snap['volume_size'],
)
开发者ID:lardcanoe,项目名称:aws_inventory,代码行数:29,代码来源:show_inventory.py
示例2: display
def display(self, cols):
# Create the maxCols list which represents the max
# length of each row element.
maxCols = []
for i in range(0, len(cols[0])):
maxCols.append(0)
for row in cols:
for i in range(0, len(row)):
if len(row[i]) > maxCols[i]:
maxCols[i] = len(row[i])
# Print the table using maxCols list to force all
# columns in the rows to line up. The first column
# (hostname) is left justified, and the subsequent
# columns are right justified.
for row in cols:
for i in range(0, len(row)):
if i == 0:
print string.ljust(row[i], maxCols[i]),
else:
print string.rjust(row[i], maxCols[i]),
if i < len(row)-1:
print '\t',
print
开发者ID:rocksclusters-attic,项目名称:ganglia,代码行数:27,代码来源:format.py
示例3: _write_atomic_coordinates
def _write_atomic_coordinates(self, f, atoms):
"""Write atomic coordinates.
Parameters:
- f: An open file object.
- atoms: An atoms object.
"""
species, species_numbers = self.species(atoms)
f.write('\n')
f.write('AtomicCoordinatesFormat Ang\n')
f.write('%block AtomicCoordinatesAndAtomicSpecies\n')
for atom, number in zip(atoms, species_numbers):
xyz = atom.position
line = string.rjust(' %.9f' % xyz[0], 16) + ' '
line += string.rjust(' %.9f' % xyz[1], 16) + ' '
line += string.rjust(' %.9f' % xyz[2], 16) + ' '
line += str(number) + '\n'
f.write(line)
f.write('%endblock AtomicCoordinatesAndAtomicSpecies\n')
f.write('\n')
origin = tuple(-atoms.get_celldisp().flatten())
f.write('%block AtomicCoordinatesOrigin\n')
f.write(' %.4f %.4f %.4f\n' % origin)
f.write('%endblock AtomicCoordinatesOrigin\n')
f.write('\n')
开发者ID:rosswhitfield,项目名称:ase,代码行数:26,代码来源:base_siesta.py
示例4: SearchNextEpisode
def SearchNextEpisode(SHOW,LASTEPISODECOMPLETE):
LASTSEASON="%s" % (int(round(LASTEPISODECOMPLETE/100)))
LASTSEASON=string.rjust(LASTSEASON,2,"0")
Message("Last season = %s" % LASTSEASON,3)
LASTEPISODE="%s" % int(LASTEPISODECOMPLETE-(int(LASTSEASON)*100))
LASTEPISODE=string.rjust(LASTEPISODE,2,"0")
Message("Last episode = %s" % LASTEPISODE,3)
NEXTEPISODE=int(LASTEPISODE)+1
NEXTEPISODE="S%sE%s" % (LASTSEASON,string.rjust("%s" % NEXTEPISODE,2,"0"))
NEXTSEASON=string.rjust("%s" % (int(LASTSEASON)+1),2,"0")
ANOTHERNEXTEPISODE="S%sE01" % NEXTSEASON
Message("III Possible next episodes are '%s' and '%s'" % (NEXTEPISODE,ANOTHERNEXTEPISODE))
URL="%s/%s.%s/" % (URLBASE,SHOW,NEXTEPISODE)
CONTENT=GetURLContent(URL)
NEXTREALEPISODE="0000"
if CONTENT == False or "did not match any documents" in CONTENT:
URL="%s/%s.%s/" % (URLBASE,SHOW,ANOTHERNEXTEPISODE)
CONTENT=GetURLContent(URL)
if CONTENT == False or "did not match any documents" in CONTENT:
Message("WWW I couldn't find any episode available for '%s'" % SHOW)
else:
NEXTREALEPISODE=ANOTHERNEXTEPISODE
else:
NEXTREALEPISODE=NEXTEPISODE
Message("III Found next episode '%s'" % NEXTREALEPISODE)
return CONTENT,NEXTREALEPISODE
开发者ID:ajdelgado,项目名称:next_episode.py,代码行数:27,代码来源:next_episodes_kat.py
示例5: draw_alarm
def draw_alarm(color):
frontbuffer(TRUE)
Gl.c3i(color)
pushmatrix()
rotate(-((Gl.alarm_time/12)%3600), 'z')
bgnpolygon()
v2f( 0.00,1.00)
v2f( 0.04,1.05)
v2f(-0.04,1.05)
endpolygon()
popmatrix()
#
pushmatrix()
rotate(-((Gl.alarm_time)%3600), 'z')
bgnpolygon()
v2f( 0.00,1.05)
v2f( 0.07,1.10)
v2f(-0.07,1.10)
endpolygon()
popmatrix()
#
cmov2(-1.06, -1.06)
charstr(string.rjust(`Gl.alarm_time/3600`,2))
charstr(':')
charstr(string.zfill((Gl.alarm_time/60)%60,2))
frontbuffer(FALSE)
开发者ID:asottile,项目名称:ancient-pythons,代码行数:26,代码来源:mclock.py
示例6: create_top_sense_tables
def create_top_sense_tables(doc_list):
documents = doc_list
if documents is None:
documents = default_document_list()
log.info("Top words")
log.info("=" * 80)
for document in documents:
log.info("=" * 80)
log.info(document.name)
try:
for word, _ in document.top_words():
log.info(word)
except AttributeError:
log.exception("No top words found. Trying to calculate them.")
with open("paper/top_senses_%s.tex" % clean_name(document.name), "w") as tex_table:
tex_table.write("""
\\begin{center}
\\begin{tabular}{ | l | l | l | }
\hline
\multicolumn{3}{|c|}{%s} \\\\ \hline
\# & Word \\\\ \hline\n""" % document.name[:30])
top_senses = document.top_senses()
last = len(top_senses)
for index, sense in enumerate(top_senses, start=1):
log.info("Sense %s -- %s " % (string.rjust(sense.name, 35), string.rjust(sense.definition, 55)))
tex_table.write("%s & %s & %s \\\\ \hline" % (index, string.rjust(sense.name, 35).split('.')[0].strip().replace('_', '\_'), sense.definition))
if index != last:
tex_table.write("\n")
tex_table.write("""\end{tabular}\n\end{center}""")
开发者ID:finiteautomata,项目名称:leninanalysis,代码行数:32,代码来源:top_senses_tables.py
示例7: output_result
def output_result(results, file):
# file output
filename, file_size = file
filename = ljust(filename[:19], 19)
file_size = get_string_size(file_size)
file_size = rjust(file_size[:9], 9)
file_string = u'%s %s' % (filename, file_size)
parser_output = u''
# output 1
parser_name, result = results[0]
if result is None:
output1 = center(u'FAILED', 21)
else:
time_spent, memory = result
memory = get_string_size(memory)
# time_spent ok already like ___.___ ms or s or mn
output1 = rjust(u'%s / %s' % (time_spent, memory), 21)
# output 2
parser_name, result = results[1]
if result is None:
output2 = center(u'FAILED', 21)
else:
time_spent, memory = result
memory = get_string_size(memory)
# time_spent ok already like ___.___ ms or s or mn
output2 = rjust(u'%s / %s' % (time_spent, memory), 21)
print '%s | %s | %s ' % (file_string, output1, output2)
开发者ID:kennym,项目名称:itools,代码行数:30,代码来源:bench_xml.py
示例8: searchstr
def searchstr(srcname, searching, TEXTCASE, DISPLAY):
global counter
print "Searching string \"" + searching + "\" in " + srcname
src = openread(srcname)
if not src: return
linenum = 0
if TEXTCASE == FALSE:
searching = string.lower(searching)
while 1:
line = src.readline()
if not line: break
linenum = linenum + 1
if TEXTCASE == FALSE: line = string.lower(line)
# Locating, counting and displaying
if string.find(line, searching) != -1:
if DISPLAY == TRUE: print string.rjust(str(linenum), 4), line,
counter = counter + string.count(line, searching)
src.close()
return counter
开发者ID:2Habibie,项目名称:ctocpp,代码行数:27,代码来源:search.py
示例9: tableWrite
def tableWrite(t, fileName=None, **args) :
'''Output a table out of a list of lists; elements number i
of each list form row i of the table
Usage :
tableWrite((list1,list2...)) - write table to stdout
tableWrite((list1,list2...), fileName) - write table to file
'''
import sys
if fileName is not None :
fileHandle = open(fileName, "w")
else :
fileHandle = sys.stdout
if 'headings' in args :
headings = args['headings']
else :
headings = None
d = len(t)
n = len(t[0])
print d,n
maxlen=numpy.zeros(d)
if headings != None :
assert len(headings) == d
for i in range(n) :
for j in range(d) :
if type(t[j][i]) == type(1.0) :
s = "%f" % t[j][i]
else :
s = str(t[j][i])
if len(s) > maxlen[j] :
maxlen[j] = len(s)
if headings != None :
for j in range(d) :
if len(headings[j]) > maxlen[j] :
maxlen[j] = len(headings[j])
print >> fileHandle, "%s" % string.center(headings[j], maxlen[j]),
print >> fileHandle
for i in range(n) :
for j in range(d) :
if type(t[j][i]) == type("") :
print >> fileHandle, "%s" % string.ljust(t[j][i], maxlen[j]),
elif type(t[j][i]) == type(1) :
print >> fileHandle, "%s" % string.rjust(str(t[j][i]), maxlen[j]),
elif type(t[j][i]) == type(1.0) :
s = "%f" % t[j][i]
print >> fileHandle, "%s" % string.rjust(s, maxlen[j]),
else :
print >> fileHandle, "%s" % ' ' * maxlen[j],
print "unknown data type"
print >> fileHandle
开发者ID:Grater,项目名称:Sentiment-Analysis,代码行数:60,代码来源:myio.py
示例10: avgValue
def avgValue(self, element, stats):
# Takes in values, averages, formats, and returns them
# Scalar input: (val1, val2)
# Vector input: vectorRange:(mag1, mag2, dir1, dir2)
valStr = ""
if stats is None:
return valStr
if element.dataType() == "Vector":
mag1 = stats[0]
mag2 = stats[1]
#print "stats", stats
dir1 = stats[2]
dir2 = stats[3]
mag, dir = self.vectorAverage((mag1, dir1),(mag2, dir2))
mag = self.callMethod(mag, element.conversion())
mag = self.round(mag, "Nearest", element.roundVal())
if mag <= self.table_wind_threshold():
valStr = self.table_light_winds_phrase()
else:
valStr = self.fformat(mag, element.roundVal())
valStr = string.rjust(valStr, element.maxWidth())
# put in the direction
dir = self.convertDirection(dir)
valStr = string.rjust(dir, 2) + valStr
else:
val1 = self.average(stats[0], stats[1])
val1 = self.callMethod(val1, element.conversion())
val = self.round(val1, "Nearest", element.roundVal())
valStr = self.fformat(val, element.roundVal())
valStr = string.rjust(valStr, element.maxWidth())
return valStr
开发者ID:KeithLatteri,项目名称:awips2,代码行数:34,代码来源:SimpleTableUtils.py
示例11: search
def search(filename, searching, TEXTCASE, DISPLAY):
print "Searching identifier " + searching + " in " + filename
global counter
f = openread(filename) # Local function
if not f: return
slen = len(searching)
linenum = 0
while 1:
line = f.readline()
if not line: break
linenum = linenum + 1
old = counter
words = split(line) # local split
for cmp in words:
if searching == cmp: counter = counter + 1
else:
if TEXTCASE == FALSE:
if string.lower(searching) == string.lower(cmp):
counter = counter + 1
if counter > old:
if DISPLAY == TRUE:
# A trailing comma to avoid new line
print string.rjust(str(linenum), 4), line,
f.close()
return counter
开发者ID:2Habibie,项目名称:ctocpp,代码行数:32,代码来源:search.py
示例12: singleValue
def singleValue(self, element, stats):
# Takes in one value, formats, and returns it
# If vector type, stats is mag,dir where direction can
# be mag or dir
valStr = ""
if stats is None:
return valStr
if element.dataType() == "Vector":
mag = self.callMethod(stats[0], element.conversion())
mag = self.round(mag,"Nearest",element.roundVal())
if mag <= self.table_wind_threshold():
valStr = self.table_light_winds_phrase()
else:
magStr = self.fformat(mag, element.roundVal())
magStr = string.rjust(magStr, element.maxWidth())
dir = stats[1]
if type(dir) is not types.StringType:
dir = self.round(dir,"Nearest",element.roundVal())
dirStr = self.convertDirection(dir)
else:
dirStr = dir
valStr = string.rjust(dirStr,2) + magStr
else:
val = self.callMethod(stats, element.conversion())
value = self.round(val, "Nearest", element.roundVal())
valueStr = self.fformat(value, element.roundVal())
valStr = string.rjust(valueStr, element.maxWidth())
return valStr
开发者ID:KeithLatteri,项目名称:awips2,代码行数:31,代码来源:SimpleTableUtils.py
示例13: _addSnowEntries
def _addSnowEntries(self, analysisList, timePeriods, editArea):
# Snow entry processing. Returns ranges of snow values in the
# edit area for each of the periods.
# Example: 0102/0202/0000. Will return "MMMM" for missing periods.
# This function will "calculate" a snow range if a single value
# is provided to it, to make the output more realistic.
returnString = " "
for period, label in timePeriods:
statDict = self.getStatDict(self._sampler, analysisList,
period, editArea)
stats = self.getStats(statDict, "SnowAmt__minMaxSum")
if stats is None:
returnString = returnString + "MMMM/" #Missing Data
else:
minV, maxV, sumV = stats
minAdj, maxAdj = self._adjustSnowAmounts(minV, maxV, sumV)
minString = string.rjust(`int(round(minAdj))`, 2)
maxString = string.rjust(`int(round(maxAdj))`, 2)
if minString[0] == " ": # fill in leading zero
minString = "0" + minString[1:]
if maxString[0] == " ": # fill in leading zero
maxString = "0" + maxString[1:]
returnString = returnString + minString + maxString + "/"
# strip off the final "/"
if returnString[-1] == "/":
returnString = returnString[:-1]
return returnString
开发者ID:KeithLatteri,项目名称:awips2,代码行数:30,代码来源:CCF.py
示例14: endElement
def endElement(self, name):
# end of </keybind> item
if name == 'keybind':
self.in_action = 0
self.has_command = 0
# remove last keybinding from the current keychain
self.in_keybind -= 1
self.keybind2 = re.sub(" [^ ]+$","",self.keybind2)
# make sure we don't carry unused names across to next keybinding
self.name = ''
# end of </name> item
elif (name == 'name'):
self.in_name = 0
# print menu item after end of </command> item (which is in a <keybind ...> item)
elif (name == 'command') and self.in_keybind:
print '<item label="' + self.keybind2 + rjust(strip(self.name),100) + \
'">\n<action name="execute"><execute>' + self.editCommand() + '</execute></action>\n</item>'
self.name = ''
# print menu item after end of </action> item (within <keybind ...> item)
# unless a <command> item has already been printed
elif (name =='action') and (self.in_keybind > 0) and (not self.has_command):
# if there's no <name> item for this action, print the action name
if self.name == '':
print '<item label="' + self.keybind2 + rjust(self.action,100) + \
'">\n<action name="execute"><execute>' + self.editCommand() + '</execute></action>\n</item>'
# otherwise print the <name>
else:
print '<item label="' + self.keybind2 + rjust(strip(self.name),100) + \
'">\n<action name="execute"><execute>' + self.editCommand() + '</execute></action>\n</item>'
self.name = ''
开发者ID:vapniks,项目名称:ob-pipe-menus,代码行数:30,代码来源:show_ob_keybindings.py
示例15: disassemble
def disassemble(co, lasti):
code = co.co_code
labels = findlabels(code)
n = len(code)
i = 0
while i < n:
c = code[i]
op = ord(c)
if op = SET_LINENO and i > 0: print # Extra blank line
if i = lasti: print '-->',
else: print ' ',
if i in labels: print '>>',
else: print ' ',
print string.rjust(`i`, 4),
print string.ljust(opname[op], 15),
i = i+1
if op >= HAVE_ARGUMENT:
oparg = ord(code[i]) + ord(code[i+1])*256
i = i+2
print string.rjust(`oparg`, 5),
if op in hasconst:
print '(' + `co.co_consts[oparg]` + ')',
elif op in hasname:
print '(' + co.co_names[oparg] + ')',
elif op in hasjrel:
print '(to ' + `i + oparg` + ')',
print
开发者ID:asottile,项目名称:ancient-pythons,代码行数:27,代码来源:dis.py
示例16: credits
def credits():
'''Shows the credits for compmake.'''
print(banner)
print "Compmake is brought to you by:\n"
for credits in contributors:
print string.rjust(credits.name, 30) + (" " * 10) + credits.what
开发者ID:welinder,项目名称:compmake,代码行数:7,代码来源:credits.py
示例17: show_config
def show_config(file): # @ReservedAssignment
config_sections = CompmakeGlobalState.config_sections
config_switches = CompmakeGlobalState.config_switches
ordered_sections = sorted(config_sections.values(),
key=lambda section: section.order)
max_len_name = 1 + max([len(s.name) for s in config_switches.values()])
max_len_val = 1 + max([len(str(get_compmake_config(s.name)))
for s in config_switches.values()])
for section in ordered_sections:
file.write(" ---- %s ---- \n" % section.name)
if section.desc:
# XXX multiline
file.write(" | %s \n" % section.desc)
for name in section.switches:
switch = config_switches[name]
value = get_compmake_config(name)
changed = (value != switch.default_value)
if changed:
attrs = ['bold']
else:
attrs = []
value = str(value)
desc = str(switch.desc)
file.write(" | %s %s %s\n" %
(compmake_colored(rjust(name, max_len_name), attrs=['bold']),
compmake_colored(rjust(value, max_len_val), attrs=attrs),
desc))
开发者ID:pombredanne,项目名称:compmake,代码行数:31,代码来源:structure.py
示例18: printData
def printData(self):
fd = self.getOutputFD()
entries = self.getData()
mostrecent = None
largest = 0
for entry in entries:
datestring = entry.YYYYMMDD
dateint = string.atoi(datestring)
if dateint > largest:
largest = dateint
fd.write(self.getServer() + ' -- ' + str(largest) + '\n')
print "Partition K_DiskSize K_Free %_Committed"
for entry in entries:
if string.atoi(entry.YYYYMMDD) == largest:
partstring = string.rjust(entry.partition, 9)
kdiskstring = string.rjust(entry.kdisksize, 12)
kfreestring = string.rjust(entry.kfree, 12)
kfreeint = string.atoi(kfreestring)
try:
floater = string.atof(entry.perccomm)
except:
pass
if floater > self.getPercentCommittedThreshold() or kfreeint < self.getKFreeThreshold():
WarnString = '*** WARNING! ***'
else:
WarnString = ''
perccommstring = str('%.2f' % floater)
perccommstring = string.rjust(perccommstring, 10)
print partstring, kdiskstring, kfreestring, perccommstring, WarnString
开发者ID:jblaine,项目名称:AFS-Tool-Suite,代码行数:29,代码来源:afs_stats.py
示例19: show_config
def show_config(file):
from compmake.utils.visualization import colored
ordered_sections = sorted(config_sections.values(),
key=lambda section: section.order)
max_len_name = 1 + max([len(s.name) for s in config_switches.values()])
max_len_val = 1 + max([len(str(compmake_config.__dict__[s.name]))
for s in config_switches.values()])
for section in ordered_sections:
file.write(" ---- %s ---- \n" % section.name)
if section.desc:
# XXX multiline
file.write(" | %s \n" % section.desc)
for name in section.switches:
switch = config_switches[name]
value = compmake_config.__dict__[name]
changed = (value != switch.default_value)
if changed:
attrs = ['bold']
else:
attrs = []
value = str(value)
desc = str(switch.desc)
file.write(" | %s %s %s\n" %
(colored(rjust(name, max_len_name), attrs=['bold']),
colored(rjust(value, max_len_val), attrs=attrs),
desc))
开发者ID:welinder,项目名称:compmake,代码行数:30,代码来源:__init__.py
示例20: print_items
def print_items(self, max_items):
import os
import string
from findtorrent.core.colors import colors
from hurry.filesize import size, si
cols = int(os.popen('stty size', 'r').read().split()[1])
print colors.HEADER + \
'No. Name' + (cols - 33) * ' ' + 'Size Files Seed Leech'
print cols * '-'
for index, item in enumerate(Items.sorted):
if (max_items != -1 and index + 1 > max_items):
break
print colors.INDEX + string.ljust(str(index + 1) + '.', 5) + \
colors.NAME + string.ljust(item['name'][:cols - 31],
cols - 31) + \
colors.SIZE + string.rjust(size(item['size'],
system=si), 6) + \
colors.FILES + string.rjust(str(item['files']) \
.replace('-1', 'N/A'), 7) + \
colors.SEED + string.rjust(str(item['seed']) \
.replace('-1', 'N/A'), 6) + \
colors.LEECH + string.rjust(str(item['leech']) \
.replace('-1', 'N/A'), 7) + \
colors.ENDC
开发者ID:ok100,项目名称:findtorrent,代码行数:25,代码来源:items.py
注:本文中的string.rjust函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论