本文整理汇总了Python中string.center函数的典型用法代码示例。如果您正苦于以下问题:Python center函数的具体用法?Python center怎么用?Python center使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了center函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_playerOrder
def get_playerOrder(players, playerOrder_val):
playerOrder = [0, 0, 0]
print "We will now play the Toss-Up Spin for possession of The Wheel in the first"
print "round."
print string.center(("-" * 80), 80)
raw_input ("Press 'ENTER' to continue: ")
for i in (0, 1, 2):
if i == 0:
print players[i] + " will spin first."
print "Get ready! " + players[i] + " is up next."
print "It is " + players[i] + "'s turn to spin."
## print string.center(("-" * 80), 80)
raw_input("Press 'ENTER' to spin The Wheel. ")
print string.center(("-" * 80), 80)
print string.center((players[i] + " received $" + str(i * 100) + "."), 80)
print string.center(("-" * 80), 80)
for j in (0, 1):
if j == 0:
playerOrder_val[i][j] = (i * 100)
else:
playerOrder_val[i][j] = players[i]
playerOrder_val.sort(reverse=True)
for i in range(3):
playerOrder[i] = playerOrder_val[i][1]
print "Congratulations,", playerOrder[0] + "! You have won the Toss-Up Spin and will take possession"
print "of The Wheel at the beginning of the first round."
print ""
print playerOrder[1] + " will Take possession of The Wheel after", playerOrder[0] + ", followed by", playerOrder[2] + "."
print string.center(("-" * 80), 80)
raw_input ("Press 'ENTER' to continue: ")
return playerOrder
示例2: load_edbfile
def load_edbfile(file=None):
"""Load the targets from a file"""
import ephem,string,math
if file is None:
import tkFileDialog
try:
file=tkFileDialog.askopenfilename()
except:
return
if file is None or file == '':
return
f=open(file)
lines=f.readlines()
f.close()
for line in lines:
p=line.split(',')
name=p[0].strip().upper()
mpc_objs[name]=ephem.readdb(line)
mpc_objs[name].compute()
objInfoDict[name]="%6s %6s %6s\n" % ( string.center("a",6),
string.center("e",6),
string.center("i",6) )
objInfoDict[name]+="%6.2f %6.3f %6.2f\n" % (mpc_objs[name]._a,mpc_objs[name]._e,math.degrees(mpc_objs[name]._inc))
objInfoDict[name]+="%7.2f %7.2f\n" % ( mpc_objs[name].earth_distance, mpc_objs[name].mag)
doplot(mpc_objs)
示例3: convert1
def convert1(self, strIn):
"Convert Unicode strIn to PinYin"
length, strOutKey, strOutValue, i=len(strIn), "", "", 0
while i<length:
code1 =ord(strIn[i:i+1])
if code1>=0x4e02 and code1<=0xe863:
strTemp = self.getIndex(strIn[i:i+1])
if not self.has_shengdiao:
strTemp = strTemp[:-1]
strLength = len(strTemp)
if strLength<1:strLength=1
strOutKey += string.center(strIn[i:i+1], strLength)+" "
strOutValue += self.spliter + string.center(strTemp, strLength) + self.spliter
else:#ascii code;
strOutKey+=strIn[i:i+1]+" "
strOutValue+=strIn[i:i+1] + ' '
i+=1
#############################
#txlist = utf8String.split()
#out=convert.convert(utf8String)
#l=[]
#for t in map(convert.convert, txlist):
# l.append(t[0])
#v = '-'.join(l).replace(' ','').replace(u'--','-').strip('-')
#############################
return [strOutValue, strOutKey]
示例4: writerow
def writerow(self, row, sep=None, *args, **kwargs):
"""
Write General Data row to file
"""
if not self.has_header: # Write basic header for raw data
self.file.write(self.encode.write_header() + '\n')
self.has_header = True
if sep is None:
sep = self.default_sep
if sep not in [',', ';', '|', ':']:
raise AdtmError('Invalid Row Value Seperator ("{0:s}") provided, '
'must be ( "," | ";" | "|" | ":" )'.format(sep))
self.offset += 1
if self.offset - self.last_headerrow == 5*5:
self.file.write("#" + sep.join((string.center(h, w) for h, w in
izip_longest(self.headers,
self.col_width,
fillvalue=0)))[1:]
+ "\n")
self.last_headerrow = self.offset
self.last_seprow = self.offset
self.offset += 1
elif self.offset - self.last_seprow == 5:
self.file.write("#" + sep.join((string.center(" ", w) for w in
self.col_width))[1:]
+ "\n")
self.last_seprow = self.offset
self.offset += 1
self.file.write(sep.join((string.center(self.encode(i), w) for i, w in
izip_longest(row,
self.col_width,
fillvalue=0)))
+ "\n")
示例5: 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)
示例6: output_success
def output_success():
# print information about success matches
if opts.summary or opts.verbose:
print "\n ------------------------------------------------------------------------------"
print string.center(">>>>> Successful matches <<<<<", 80)
print " ------------------------------------------------------------------------------"
s_success = sorted(success, key=lambda k: k['name']) # group by site name
# print normal summary table on request (--summary)
if not opts.verbose and opts.summary:
print "\n ------------------------------------------------------------------------------"
print " ", "| Module |".ljust(35), "| Account |".ljust(28)
print " ------------------------------------------------------------------------------"
for s in s_success:
print " " + s['name'].ljust(37) + s['account'].ljust(30)
print " ------------------------------------------------------------------------------\n"
# print verbose summary on request (-v --summary)
elif opts.verbose and opts.summary:
for s in s_success:
print textwrap.fill((" NAME: \t\t\t%s" % s['name']),
initial_indent='', subsequent_indent='\t -> ', width=80)
print textwrap.fill((" ACCOUNT: \t\t%s" % s['account']),
initial_indent='', subsequent_indent='\t -> ', width=80)
print textwrap.fill((" URL: \t\t\t%s" % s['url']),
initial_indent='', subsequent_indent='\t -> ', width=80)
print textwrap.fill((" METHOD: \t\t%s" % s['method']),
initial_indent='', subsequent_indent='\t -> ', width=80)
print textwrap.fill((" POST PARAMETERS: \t%s" % s['postParameters']),
initial_indent='', subsequent_indent='\t -> ', width=80)
print " ------------------------------------------------------------------------------"
else:
print " ------------------------------------------------------------------------------\n"
示例7: createSecMarkerReport
def createSecMarkerReport ():
global annot, nonfatalCount, nonfatalReportNames
print 'Create the secondary marker report'
sys.stdout.flush()
fpSecMrkRpt.write(string.center('Secondary Marker Report',130) + NL)
fpSecMrkRpt.write(string.center('(' + timestamp + ')',130) + 2*NL)
fpSecMrkRpt.write('%-20s %-16s %-50s %-16s%s' %
('Term ID', 'Secondary MGI ID',
'Marker Symbol','Primary MGI ID',NL))
fpSecMrkRpt.write(20*'-' + ' ' + 16*'-' + ' ' + \
50*'-' + ' ' + 16*'-' + NL)
cmds = []
#
# Find any MGI IDs from the input data that are secondary IDs
# for a marker.
#
cmds.append('''
select tmp.termID,
tmp.mgiID,
m.symbol,
a2.accID
from %s tmp,
ACC_Accession a1,
ACC_Accession a2,
MRK_Marker m
where tmp.mgiID is not null and
lower(tmp.mgiID) = lower(a1.accID) and
a1._MGIType_key = 2 and
a1._LogicalDB_key = 1 and
a1.preferred = 0 and
a1._Object_key = a2._Object_key and
a2._MGIType_key = 2 and
a2._LogicalDB_key = 1 and
a2.preferred = 1 and
a2._Object_key = m._Marker_key
order by lower(tmp.mgiID), lower(tmp.termID)
''' % (tempTable))
results = db.sql(cmds,'auto')
#
# Write the records to the report.
#
for r in results[0]:
termID = r['termID']
mgiID = r['mgiID']
fpSecMrkRpt.write('%-20s %-16s %-50s %-16s%s' %
(termID, mgiID, r['symbol'], r['accID'], NL))
numErrors = len(results[0])
fpSecMrkRpt.write(NL + 'Number of Rows: ' + str(numErrors) + NL)
if numErrors > 0:
if not secMrkRptFile in nonfatalReportNames:
nonfatalReportNames.append(secMrkRptFile + NL)
nonfatalCount += numErrors
示例8: title
def title(self,title):
_l = len(title)
_p = max(_l%2 +_l,40)
_x = self.parlen -_p
if (_x > 2):
print (_x/2)*self.sep + string.center(title,_p) + (_x/2)*self.sep
else:
print string.center(text,self.parlen)
示例9: lose_a_turn
def lose_a_turn(player_turn, playerOrder):
print ""
print playerOrder[player_turn], "spun for LOSE A TURN!"
print ""
print "Sorry, " + playerOrder[player_turn] + ". Possession of The Wheel passes to " + playerOrder[(player_turn + 1) % 3] + "."
print string.center(("-" * 80), 80)
time.sleep(2.5)
示例10: print_instruments
def print_instruments():
"""Prints a display of all instruments by category and family"""
for title, category in instruments.iteritems():
print "\n" + string.center(" " + title + " ", 50, "~")
for name, family in category.iteritems():
print "\n" + string.center(" " + name + " ", 50, "-") + "\n"
print_instrument_family(family)
示例11: slove
def slove(C,I,P,N):
fout=open("fout.out","w")
for i in range(N):
for j in range(I[i]-1):
for k in range(j+1,I[i]):
if P[i][j]+P[i][k]==C[i]:
# print P[i][j],P[i][k],C[i]
fout.write(str("Case #"+str(i+1)+":"+string.center(str(j+1),3)+" "+string.center(str(k+1),2)+"\r"))
continue
示例12: printGrid
def printGrid(self):
system("clear")
print "_"*self.rowsize
for i in range(self.size):
print "|",
for j in range(self.size):
print center(str(self.grid[i][j]),self.cellwidth)+"|",
print "\n"+"_"*self.rowsize
print "Score: ",self.score
示例13: guess_previously_called
def guess_previously_called(player_turn, playerOrder, guess):
print ""
print "Sorry, '" + guess + "' has already been called in this round."
print playerOrder[(player_turn + 1) % 3] + " now takes possession of The Wheel."
print ""
print string.center(("-" * 80), 80)
time.sleep(1.5)
return playerOrder
示例14: draw_grid
def draw_grid(
screen, questions,
selected_question, answered_questions,
player_scores ):
height, width = screen.getmaxyx()
columns = len(questions)
rows = len(questions[0]["questions"])
# take the total screen width, subtract the border zone,
# and allow INNER_GRID_BORDER space between each column
category_width = ( width-GRID_HORIZ_BORDER*2-
(columns-1)*INNER_GRID_BORDER ) // columns
question_grid_start = GRID_VERT_OFFSET + SPACE_FROM_CATEGORY_TO_LEVELS
for i, category in enumerate(questions):
category_name = (category["name"]
if len(category["name"]) <= category_width
else category["abrev_name"][:category_width]
)[:category_width]
horizontal_position = (
GRID_HORIZ_BORDER + i*category_width +
i*INNER_GRID_BORDER
)
screen.addstr(
GRID_VERT_OFFSET,
horizontal_position,
center(category_name, category_width, " "),
CURSES_COLOUR_PAIR_GOOD_FEEL
)
for j, score in enumerate(POINTS):
cur_color = CURSES_COLOUR_PAIR_GOOD_FEEL
if (i, score) == tuple(selected_question):
if (i, score) in answered_questions:
cur_color = CURSES_COLOUR_PAIR_MEH
else:
cur_color = CURSES_COLOUR_PAIR_REALLY_GOOD
elif (i, score) in answered_questions:
cur_color = CURSES_COLOUR_PAIR_BAD_FEEL
screen.addstr(
question_grid_start + j+j*VERT_INNER_GRID_BORDER,
horizontal_position,
center(str(score), category_width, " "),
cur_color )
player_scores_str = PLAYER_SEP_CHARS.join(player_scores)
player_scores_str = \
player_scores_str[:(width-GRID_PLAYER_SCORES_HORIZ_OFFSET)]
screen.addstr(height-2, GRID_PLAYER_SCORES_HORIZ_OFFSET,
player_scores_str,
CURSES_COLOUR_PAIR_MAX_CONTRAST )
示例15: writeInvcoordStrandHeader
def writeInvcoordStrandHeader():
print 'Create the invalid coordinate and strand report'
fpInvCoordStrandRpt.write(string.center('Invalid Coordinate and Strand Report',110) + NL)
fpInvCoordStrandRpt.write(string.center('(' + timestamp + ')',110) + 2*NL)
fpInvCoordStrandRpt.write('%-12s %-20s %-20s %-10s %-20s %-30s%s' %
('MGI ID','Start Coordinate','End Coordinate', 'Strand',
'Provider','Reason',NL))
fpInvCoordStrandRpt.write(12*'-' + ' ' + 20*'-' + ' ' + 20*'-' + ' ' + \
10*'-' + ' ' + 20*'-' + ' ' + 30*'-' + NL)
return