本文整理汇总了Python中outputty.Table.insert方法的典型用法代码示例。如果您正苦于以下问题:Python Table.insert方法的具体用法?Python Table.insert怎么用?Python Table.insert使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类outputty.Table
的用法示例。
在下文中一共展示了Table.insert方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_table_insert
# 需要导入模块: from outputty import Table [as 别名]
# 或者: from outputty.Table import insert [as 别名]
def test_table_insert(self):
table = Table(headers=["python", "rules"])
table.extend([[1, 2], [3, 4], [5, 6], [7, 8], [1, 2]])
table.insert(0, [4, 2])
table.insert(1, {"python": 9, "rules": 9})
self.assertEquals(table[0], [4, 2])
self.assertEquals(table[1], [9, 9])
self.assertEquals(len(table), 7)
示例2: Table
# 需要导入模块: from outputty import Table [as 别名]
# 或者: from outputty.Table import insert [as 别名]
table = Table(headers=["City", "State", "Country"])
table.append(["Três Rios", "Rio de Janeiro", "Brazil"])
table.append(["Niterói", "Rio de Janeiro", "Brazil"])
table.append(["Rio de Janeiro", "Rio de Janeiro", "Brazil"])
table.append(["Porto Alegre", "Rio Grande do Sul", "Brazil"])
table.append(["São Paulo", "São Paulo", "Brazil"])
print "First 3 rows:"
for row in table[:3]: # Slicing
print row
# Change the two last rows:
table[-2:] = [["Junín", "Buenos Aires", "Argentina"], ["Ciudad del Este", "Alto Paraná", "Paraguay"]]
# 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
示例3: Table
# 需要导入模块: from outputty import Table [as 别名]
# 或者: from outputty.Table import insert [as 别名]
table = Table(headers=['City', 'State', 'Country'])
table.append(['Três Rios', 'Rio de Janeiro', 'Brazil'])
table.append(['Niterói', 'Rio de Janeiro', 'Brazil'])
table.append(['Rio de Janeiro', 'Rio de Janeiro', 'Brazil'])
table.append(['Porto Alegre', 'Rio Grande do Sul', 'Brazil'])
table.append(['São Paulo', 'São Paulo', 'Brazil'])
print 'First 3 rows:'
for row in table[:3]:
print row
#Change the two last rows:
table[-2:] = [['Junín', 'Buenos Aires', 'Argentina'],
['Ciudad del Este', 'Alto Paraná', 'Paraguay']]
#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