Skip to content

_Columns slicing returns single _Column #770

Open
@JozsefKutas

Description

@JozsefKutas

Slicing a _Columns instance returns a single _Column:

import docx

document = docx.Document()
table = document.add_table(3, 3)
print(table.columns[1:])  # shows <docx.table._Column...>

This is similar to the behaviour for table rows raised in #84. Slicing a _Rows instance now returns a list of _Row's as expected, but this behaviour doesn't seem to be implemented by _Columns.

I had a look in table.py and it seems like _Columns and _Rows are implemented in quite different ways. This also leads to other inconsistencies, e.g. the error messages if indexes are out of bounds are different. Is there any reason for this?

My current workaround is to imitate the approach taken in _Rows:

print(list(table.columns)[1:])  # shows [<docx.table._Column ...>, <docx.table._Column ...>]

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions