本文整理汇总了Python中outputty.Table.index方法的典型用法代码示例。如果您正苦于以下问题:Python Table.index方法的具体用法?Python Table.index怎么用?Python Table.index使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类outputty.Table
的用法示例。
在下文中一共展示了Table.index方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_table_index
# 需要导入模块: from outputty import Table [as 别名]
# 或者: from outputty.Table import index [as 别名]
def test_table_index(self):
table = Table(headers=["python", "rules"])
table.extend([[1, 2], [3, 4], [5, 6], [7, 8], [1, 2], [9, 0]])
self.assertEquals(table.index([1, 2]), 0)
self.assertEquals(table.index({"python": 1, "rules": 2}), 0)
self.assertEquals(table.index([5, 6]), 2)
self.assertEquals(table.index([1, 2], 1), 4)
with self.assertRaises(ValueError):
non_ecxiste = table.index([1, 9])
with self.assertRaises(ValueError):
not_found = table.index([1, 2], 1, 3)
示例2: len
# 需要导入模块: from outputty import Table [as 别名]
# 或者: from outputty.Table import index [as 别名]
# Insert a row in the first position, using dict notation:
table.insert(0, {"City": "La Paz", "State": "La Paz", "Country": "Bolivia"})
print "New table:"
print table
print
table.reverse()
print "And the table in the reversed order:"
print table
print
popped_row = table.pop()
rio = ["Rio de Janeiro", "Rio de Janeiro", "Brazil"]
table.append(rio) # repeated row
number_of_rios = table.count(rio)
index_of_first_rio = table.index(rio)
table.remove(rio) # remove the first occurrence of this row
number_of_rows = len(table)
print "Popped row:", popped_row
print "Number of rows:", number_of_rows
print "Count of Rios rows (before remove):", number_of_rios
print "Table after pop and remove:"
print table
print
# Removing non-brazilian cities:
del table[:2]
# Let's change an entire column:
table["Country"] = ["Brasil", "Brasil", "Brasil"]
print 'Column "Country" changed:'
print table