Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #17645

Re: [Python-ideas] 回复: Columnize in module "cmd"

Date 2011-12-21 04:30 +0000
From MRAB <python@mrabarnett.plus.com>
Subject Re: [Python-ideas] 回复: Columnize in module "cmd"
References <1324349593.51908.YahooMailNeo@web92411.mail.cnh.yahoo.com> <1324350440.30993.YahooMailNeo@web92413.mail.cnh.yahoo.com> <CAP7+vJL9RRUCKhuqA7T6OLSJOsjtc9p74Yk7fwHrxwh=VJDfuw@mail.gmail.com> <1324438134.11446.YahooMailNeo@web92408.mail.cnh.yahoo.com>
Newsgroups comp.lang.python
Message-ID <mailman.3899.1324441825.27778.python-list@python.org> (permalink)

Show all headers | View raw


On 21/12/2011 03:28, Tom Zhou wrote:
> Thanks a lot for your reply!
> I've reservations, maybe code looks like:
> """
> colwidth = max(map(len, list))
> ncols = displaywidth/(colwidth+2)+1
> nrows = size/ncols+1
> for nrows
>      for ncols
>           texts = list[...]
>           output texts
> """
> is clear, and just waste some space of stdout.
>
A couple of points:

1. Trying not to use the names of built-in classes or functions for
your variable names, for example "list".

2. In Python 2 int/int returns an int, but in Python 3 int/int returns
a float. In both cases int//int returns an int (at least for recent
versions of Python 2), so it's a good idea to always use // when you
want to do integer division.

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: [Python-ideas] 回复:  Columnize in module "cmd" MRAB <python@mrabarnett.plus.com> - 2011-12-21 04:30 +0000

csiph-web