本文整理汇总了Python中table.Table类的典型用法代码示例。如果您正苦于以下问题:Python Table类的具体用法?Python Table怎么用?Python Table使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Table类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestPot
class TestPot(unittest.TestCase):
"""Do we have a fully functional pot object?"""
def setUp(self):
self.p0 = Player('p0', 100)
self.p1 = Player('p1', 100)
self.p2 = Player('p2', 100)
self.p3 = Player('p3', 100)
self.p4 = Player('p4', 100)
self.p5 = Player('p5', 100)
self.s0 = Seat('s0')
self.s1 = Seat('s1')
self.s2 = Seat('s2')
self.s3 = Seat('s3')
self.s4 = Seat('s4')
self.s5 = Seat('s5')
players = [self.p0, self.p1, self.p2, self.p3, self.p4, self.p5]
seats = [self.s0, self.s1, self.s2, self.s3, self.s4, self.s5]
self.table = Table(seats, 5, 10, 0)
self.dealer = Dealer(self.table)
self.table.dealer = self.dealer
player = 0
for seat in seats:
seat.player = players[player]
seat.player.seat = seat
seat.active = True
seat.player.table = self.table
player += 1
self.table.init_hand()
def test_who_is_first_pre_flop(self):
"""Do we make the proper player act first pre-flop??"""
self.dealer.deal_hole()
self.assertTrue(self.table.seats[self.table.under_the_gun].player.action)
def test_who_is_first_post_flop(self):
"""Do we make the proper player act first post-flop"""
self.dealer.deal_hole()
self.table.seats[self.table.under_the_gun].player.action = False
self.dealer.deal()
self.assertTrue(self.table.seats[self.table.first].player.action)
def test_bet(self):
"""Can each player bet 50?"""
self.dealer.deal_hole()
i = 0
while i < 6:
i += 1
for seat in self.table.pots[-1].seats:
print(seat.player.name, seat.player.equity, seat.player.action)
if seat.player.action:
seat.player.bet(50)
self.table.pots[-1].betting_round()
break
print(seat.player.name, seat.player.equity, seat.player.action)
print(self.table.pots[-1].pot)
示例2: _on_register
def _on_register(self, username):
self.nick = username
self.send({'registered': self.nick})
#score = self._get_score(self.nick)
#self.send({'update_score': score})
while self._waiting:
opponent = self._waiting.pop()
if opponent.is_closed:
continue
self._opponents[self.session].append(opponent)
self._opponents[opponent.session].append(self)
self.send({'status': "playing against " + opponent.nick,
'ready': True})
opponent.send({'status': "playing against " + self.nick,
'ready': True})
table_id = Table.new_table_id()
players = [self, opponent]
for player in players:
player.table_id = table_id
player.changes = 0
table = Table(players)
self._tables[table_id] = table # could be more
table.deal_5_cards_each()
for player in table.players:
player.send({'hand': player.cards})
else:
self._waiting.append(self)
self.send({'status': 'Waiting', 'color': 'orange'})
示例3: generate_time_table
def generate_time_table(self):
table = Table()
# prepare header
header = ["procedure"]
for size in self.data.sizes:
header.append('%d B' % size)
table.set_header(header)
# get data
for procedure in self.data.procedures:
data = self.data.data_for_procedure(procedure)
row = [procedure]
for item in data:
fmt = TIME_PATTERN % item.time
if item.time == self.data.get_shortest_time(item.size):
row.append('**%s**' % fmt)
else:
row.append(fmt)
table.add_row(row)
return table
示例4: display_addr_refs
def display_addr_refs(refs, ref_statuses):
table = Table(
num_cols=len(REF_COL_NAMES), width=TABLE_WIDTH, alignment='right')
table.header[:] = REF_COL_NAMES
for ref, ref_status in zip(refs, ref_statuses):
if ref.tag is not None:
ref_tag = ref.tag
else:
ref_tag = 'n/a'
if ref.index is not None:
ref_index = ref.index
else:
ref_index = 'n/a'
if ref.offset is not None:
ref_offset = ref.offset
else:
ref_offset = 'n/a'
# Display data for each address as a row in the table
table.rows.append((
ref.word_addr,
prettify_bin_addr(ref.bin_addr, MIN_BITS_PER_GROUP),
prettify_bin_addr(ref_tag, MIN_BITS_PER_GROUP),
prettify_bin_addr(ref_index, MIN_BITS_PER_GROUP),
prettify_bin_addr(ref_offset, MIN_BITS_PER_GROUP),
ref_status))
print(table)
示例5: format_table
def format_table(data):
table = Table()
keys = data[1].keys()
# prepare header
header1 = ["number of spaces"]
header2 = [""]
for key in keys:
header1.append(("%s [cycles/byte]" % key, 3))
header2.extend(["avg (min)", "avg (max)", "best"])
table.add_header(header1)
table.add_header(header2)
# add data
for cardinality in xrange(1, 64+1):
row = ['%d' % cardinality]
measurements = data[cardinality]
for meas in measurements.values():
row.append('%0.3f' % min(meas.values))
row.append('%0.3f' % max(meas.values))
row.append('%0.3f' % meas.best)
table.add_row(row)
return table
示例6: load_table
def load_table(filename):
t = Table()
seen_header = False
for line in file(filename):
if not seen_header:
seen_header = True
continue
line = line.rstrip("\n")
(id, status, price, genres, policy, countries) = line.split("\t")
def split_ints(commasep):
if commasep == '':
return set()
return set([int(s) for s in commasep.split(",")])
t.append_row(
id,
{
'status': status,
'price': int(float(price)*100),
'genre': split_ints(genres),
'policy': policy,
'country': split_ints(countries)
})
return t
示例7: generate_speedup_table
def generate_speedup_table(self):
table = Table()
# prepare header
header = ["procedure"]
for size in self.data.sizes:
header.append('%d B' % size)
table.set_header(header)
reference_time = {}
for size in self.data.sizes:
time = self.data.get(self.data.procedures[0], size)
reference_time[size] = time
# get data
for proc in self.data.procedures:
measurments = self.data.data_for_procedure(proc)
row = [proc]
for item in measurments:
speedup = reference_time[item.size] / item.time
row.append('%0.2f' % speedup)
table.add_row(row)
return table
示例8: reset
def reset(cls):
"""Reset to default state."""
Box.reset()
Note.reset()
Figure.reset()
Table.reset()
Video.reset()
示例9: result
def result(self):
""" Perform the query, and return the result as a Table object """
BaseQuery.logger.log( "With arguments: " + str(self.arguments) )
BaseQuery.logger.log( "Running query: \n" + str(self.complete_query) )
cursor = self.db_connection.cursor()
start_time = time.time()
cursor.execute( self.complete_query )
self.elapsed_time = time.time() - start_time
BaseQuery.logger.log( str(self.elapsed_time) + " seconds" )
results_table = Table()
for col in cursor.description:
results_table.append_column( col[0] )
row = cursor.fetchone()
while row:
results_table.append_row( [self.output_clean_function(i) for i in row] )
row = cursor.fetchone()
self.rows_fetched = len(results_table)
BaseQuery.logger.log( str(self.rows_fetched) + " rows fetched" )
return results_table
示例10: createTable
def createTable(**kwargs):
""" CREATE table.
kwargs['cols'] is a list of consecutive column name - type pairs
i.e. [col1_name, col1_type, col2_name, col2_type, ...] which is why
it gets split when calling Table.create()
"""
Table.create(kwargs['table'], kwargs['cols'][::2], kwargs['cols'][1::2])
示例11: login
def login(self, *args):
global w
name = w.loginEdit.text()
password = w.passwordEdit.text()
if User.login(name, password):
w = Table()
w.show()
示例12: test_get_table
def test_get_table(self):
try:
data = TG.build_table_from_txt(D.analog_1)
table = Table(data)
check = table.get_table()
self.assertIs(data, check)
except:
self.assert_(False)
示例13: test_get_length
def test_get_length(self):
try:
data = TG.build_table_from_txt(D.analog_1)
table = Table(data)
length = table.get_length()
self.assertEqual(len(data), length)
except:
self.assert_(False)
示例14: apply
def apply(self, tables):
columns = self.get_columns(tables)
table = tables[0]
measure_column = table[self['measure']]
new_column_headers = []
header_column = columns[0]
start_row = 0
end_row = table.rows()
for v in header_column.data:
if(not v in new_column_headers):
new_column_headers.append(v)
key_columns = filter(lambda x: not x.name in [measure_column.name, header_column.name], table)
reduction = {}
reduction_index = 0
new_table = Table()
for col in key_columns:
new_table.add_column(col.name, {})
#this name lookup is needed since table implementation changes names under certain circumstances
name_lookup = {}
for header in new_column_headers:
col = new_table.add_column(header, {})
name_lookup[header] = col.name
for row in range(start_row, end_row):
key = '*'.join([col[row] for col in key_columns])
if(not reduction.has_key(key)):
reduction[key] = reduction_index
for col in key_columns:
new_table[col.name][reduction_index] = col[row]
reduction_index += 1
index = reduction[key]
header = header_column[row]
measure = measure_column[row]
new_table[name_lookup[header]][index] = measure
table.clear()
for col in new_table:
table.insert_column(col, {})
示例15: __call__
def __call__(self, category, player_id, dct):
table_name = 'gc_cur_team_stats_{0}'.format(category)
table = Table(table_name)
table.insert(
self.cursor,
getattr(values, table_name)(
self.gc_cur_team_id,
player_id,
dct))