将标题从黄瓜数据表的顶部移到另一侧-Python [英] Move the headings from top of Cucumber's Data Table to side - Python
问题描述
我正在寻找将Cucumber数据表的标题更改为侧面的方法.因此,它将使特征文件可读.
I am looking for the ways to change the headings of Cucumber's Data Table to the side. So it will make the feature file readable.
常规方式:
| Name | Email | Phone No. | ......... |
| John | i@g.net | 098765644 | ......... |
它可能是一个非常宽的数据表,我不得不来回滚动.
It can be a very wide data table and I would have to scroll back and forth.
所需方式:
| Name | John |
| Email | i@g.net |
| Phone No. | 098765444 |
.
.
.
Java和Ruby中有少量示例.但是我正在使用Python.
There are a small number of examples in Java and Ruby. But I am working with Python.
我尝试了很多不同的事情,例如numpy.transpose(),将它们转换为列表.但这是行不通的,因为数据表的格式为:
I had tried many different things like numpy.transpose(), converting them to list. But it won't work because the Data Table's format is:
[<Row['Name','John'],...]
推荐答案
这看起来与numpy无关.
This doesn't look like it's related to numpy.
旋转列表列表通常使用zip(* the_list)
pivoting a list of list is often done with zip(*the_list)
这将返回一个透视的行为表
This will return a pivoted behave table
from behave.model import Table
class TurnTable(unittest.TestCase):
"""
"""
def test_transpose(self):
table = Table(
['Name', 'John', 'Mary'],
rows=[
['Email', "john@example.com", "mary@example.com"],
['Phone', "0123456789", "9876543210"],
])
aggregate = [table.headings[:]]
aggregate.extend(table.rows)
pivoted = list(zip(*aggregate))
self.assertListEqual(pivoted,
[('Name', 'Email', 'Phone'),
('John', 'john@example.com', '0123456789'),
('Mary', 'mary@example.com', '9876543210')])
pivoted_table = Table(
pivoted[0],
rows=pivoted[1:])
mary = pivoted_table.rows[1]
self.assertEqual(mary['Name'], 'Mary')
self.assertEqual(mary['Phone'], '9876543210')
您还可以查看 https://pypi.python.org/pypi/pivottable
这篇关于将标题从黄瓜数据表的顶部移到另一侧-Python的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!