本文整理汇总了Python中outputty.Table.append_column方法的典型用法代码示例。如果您正苦于以下问题:Python Table.append_column方法的具体用法?Python Table.append_column怎么用?Python Table.append_column使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类outputty.Table
的用法示例。
在下文中一共展示了Table.append_column方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_append_column_should_raise_ValueError_when_column_already_exists
# 需要导入模块: from outputty import Table [as 别名]
# 或者: from outputty.Table import append_column [as 别名]
def test_append_column_should_raise_ValueError_when_column_already_exists(self):
table = Table(headers=["python", "rules"])
table.extend([[1, 2], [3, 4], [5, 6]])
with self.assertRaises(ValueError):
table.append_column("python", [3, 5, 7])
self.assertEquals(table.headers, ["python", "rules"])
self.assertEquals(table[:], [[1, 2], [3, 4], [5, 6]])
示例2: test_table_append_column_should_raise_ValueError_when_wrong_size
# 需要导入模块: from outputty import Table [as 别名]
# 或者: from outputty.Table import append_column [as 别名]
def test_table_append_column_should_raise_ValueError_when_wrong_size(self):
table = Table(headers=["python", "rules"])
table.extend([[1, 2], [3, 4], [5, 6]])
with self.assertRaises(ValueError):
table.append_column("new column", [3, 5, 7, 8])
self.assertEquals(table.headers, ["python", "rules"])
self.assertEquals(table[:], [[1, 2], [3, 4], [5, 6]])
示例3: test_append_column_should_accept_a_function_to_create_new_column
# 需要导入模块: from outputty import Table [as 别名]
# 或者: from outputty.Table import append_column [as 别名]
def test_append_column_should_accept_a_function_to_create_new_column(self):
table = Table(headers=["python", "rules"])
table.extend([[1, 2], [3, 4]])
table.append_column("new column", lambda row: row[0] + row[1])
self.assertEquals(table.headers, ["python", "rules", "new column"])
self.assertEquals(table[:], [[1, 2, 3], [3, 4, 7]])
del table["new column"]
table.append_column("other column", lambda row: row[0] + row[1], position=0)
self.assertEquals(table.headers, ["other column", "python", "rules"])
self.assertEquals(table[:], [[3, 1, 2], [7, 3, 4]])
del table["other column"]
table.append_column("third column", lambda r: r["python"] * r["rules"], row_as_dict=True)
self.assertEquals(table.headers, ["python", "rules", "third column"])
self.assertEquals(table[:], [[1, 2, 2], [3, 4, 12]])
示例4: Table
# 需要导入模块: from outputty import Table [as 别名]
# 或者: from outputty.Table import append_column [as 别名]
#!/usr/bin/env python
# coding: utf-8
# title = Appending a column
#You can append a column in your `Table` object using the `append_column`
#method. You can pass new column's values or a function to generate the value
#based on row data. Let's see how it works - it's simple.
from outputty import Table
table = Table(headers=['Name', 'Creation Year'])
table.append(['Python', 1991])
table.append(['Unix', 1969])
#We have the values, so we'll append it:
table.append_column('Category', ['Programming Language', 'Operating System'])
#We can also generate the values:
table.append_column('Age', lambda row: 2012 - row[1]) #row is a list
#Our function can receive row as dict (with `row_as_dict` parameter) and we
#can insert the column where we want (with `position` parameter):
table.append_column('First Letter', lambda row: row['Name'][0],
row_as_dict=True, position=0) #row is dict
#...and the result:
print table
示例5: test_append_column_should_be_inserted_in_any_position
# 需要导入模块: from outputty import Table [as 别名]
# 或者: from outputty.Table import append_column [as 别名]
def test_append_column_should_be_inserted_in_any_position(self):
table = Table(headers=["python", "rules"])
table.extend([[1, 2], [3, 4]])
table.append_column("new column", [3, 5], position=0)
self.assertEquals(table.headers, ["new column", "python", "rules"])
self.assertEquals(table[:], [[3, 1, 2], [5, 3, 4]])
示例6: test_append_column_should_decode_strings
# 需要导入模块: from outputty import Table [as 别名]
# 或者: from outputty.Table import append_column [as 别名]
def test_append_column_should_decode_strings(self):
table = Table(headers=["python", "rules"], input_encoding="iso-8859-1")
table.extend([[1, 2], [3, 4]])
table.append_column("new column", [u"Álvaro".encode("iso-8859-1"), u"Píton".encode("iso-8859-1")])
self.assertEquals(table.headers, ["python", "rules", "new column"])
self.assertEquals(table[:], [[1, 2, u"Álvaro"], [3, 4, u"Píton"]])
示例7: test_table_append_column_should_change_headers_and_rows
# 需要导入模块: from outputty import Table [as 别名]
# 或者: from outputty.Table import append_column [as 别名]
def test_table_append_column_should_change_headers_and_rows(self):
table = Table(headers=["python", "rules"])
table.extend([[1, 2], [3, 4], [5, 6]])
table.append_column("new column", [3, 5, 7])
self.assertEquals(table.headers, ["python", "rules", "new column"])
self.assertEquals(table[:], [[1, 2, 3], [3, 4, 5], [5, 6, 7]])