当前位置: 首页>>代码示例>>Python>>正文


Python Table.append_column方法代码示例

本文整理汇总了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]])
开发者ID:andreas-andrade,项目名称:outputty,代码行数:9,代码来源:test_Table_base.py

示例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]])
开发者ID:andreas-andrade,项目名称:outputty,代码行数:9,代码来源:test_Table_base.py

示例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]])
开发者ID:andreas-andrade,项目名称:outputty,代码行数:18,代码来源:test_Table_base.py

示例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
开发者ID:rennerocha,项目名称:outputty,代码行数:27,代码来源:9_append_column.py

示例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]])
开发者ID:andreas-andrade,项目名称:outputty,代码行数:8,代码来源:test_Table_base.py

示例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"]])
开发者ID:andreas-andrade,项目名称:outputty,代码行数:8,代码来源:test_Table_base.py

示例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]])
开发者ID:andreas-andrade,项目名称:outputty,代码行数:8,代码来源:test_Table_base.py


注:本文中的outputty.Table.append_column方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。