Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #10726 > unrolled thread
| Started by | Karim <kliateni@gmail.com> |
|---|---|
| First post | 2011-08-02 14:28 +0200 |
| Last post | 2011-08-02 14:28 +0200 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.lang.python
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: Please code review. Karim <kliateni@gmail.com> - 2011-08-02 14:28 +0200
| From | Karim <kliateni@gmail.com> |
|---|---|
| Date | 2011-08-02 14:28 +0200 |
| Subject | Re: Please code review. |
| Message-ID | <mailman.1770.1312288087.1164.python-list@python.org> |
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 top | Article view | comp.lang.python
csiph-web