Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #10726
| Date | 2011-08-02 14:28 +0200 |
|---|---|
| From | Karim <kliateni@gmail.com> |
| Subject | Re: Please code review. |
| References | <4E37E34B.5080707@gmail.com> <j18p4v$og$1@dough.gmane.org> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.1770.1312288087.1164.python-list@python.org> (permalink) |
Thanks Paul,
I never used string module.
In fact, cellnames.split('') gives a syntax error w/ empty string.
That's why I use the intermediate replace() which accept that.
Cheers
Karim
On 08/02/2011 02:04 PM, Paul Kölle wrote:
> Am 02.08.2011 13:45, schrieb Karim:
>>
>> Hello,
>>
>> I need a generator to create the cellname in a excell (using pyuno)
>> document to assign value to
>> the correct cell. The following code does this but do you have some
>> optimizations
>> on it, for instance to get the alphabetic chars instead of
>> hard-coding it.
> you can use:
> import string
> cellnames = string.ascii_uppercase
>
> not sure why you need the .replace().split() stuff...
>
>
> def _xrange_cellnames(rows, cols):
> cellnames = string.ascii_uppercase
> for row in xrange(1, rows+1):
> for char in cellnames[:rows]:
> yield char + str(row)
>
> cheers
> Paul
>
>
>>
>> Cheers
>> karim
>>
>> Python 2.7.1+ (r271:86832, Apr 11 2011, 18:13:53)
>> [GCC 4.5.2] on linux2
>> Type "help", "copyright", "credits" or "license" for more information.
>> >>> def _xrange_cellnames(rows, cols):
>> ... """Internal iterator function to compute excell table cellnames."""
>> ... cellnames = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
>> ... for row in xrange(1, rows+1):
>> ... for char in cellnames.replace('', ' ').split()[:cols]:
>> ... yield char + str(row)
>> ...
>> >>> list( _xrange_cellnames(rows=3,cols=4))
>> ['A1', 'B1', 'C1', 'D1', 'A2', 'B2', 'C2', 'D2', 'A3', 'B3', 'C3', 'D3']
>>
>>
>
>
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: Please code review. Karim <kliateni@gmail.com> - 2011-08-02 14:28 +0200
csiph-web