Re: [Tutor] Puzzled again

2011-08-02 Thread Andre Engels
On Wed, Aug 3, 2011 at 8:07 AM, Richard D. Moores wrote:

> On Tue, Aug 2, 2011 at 21:59, Dave Angel  wrote:
>
> > When I paste that from your email into a file and run Python 2.7 on it,
> it
> > behaves fine with no errors.  That's in Linux.
>
> I should have said that I'm using Wing IDE Professional 4.0.3-1 (rev
> 24721), Windows Vista, and Python 3.2.1.
>
> > But the easiest explanation is that you perhaps used a funny character
> for
> > your triple-quotes.  And when you retyped them on a new line, you typed
> > regular ones.
> >
> > For example, I've seen that sort of thing when someone wrote code in a
> > Windows word processor that had "smart quotes."
>
> No, no funny characters with Wing.
>
> Thanks for your guess, Dave.
>
> But here's a try using the regular command line:
>
> C:\Windows\System32>python
> Python 3.2.1 (default, Jul 10 2011, 20:02:51) [MSC v.1500 64 bit
> (AMD64)] on win32
> Type "help", "copyright", "credits" or "license" for more information.
> >>> from mycalc import convertPath
> Traceback (most recent call last):
>   File "", line 1, in 
>  File "C:\Python32\lib\site-packages\mycalc.py", line 36
>"""
> SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes
> in position 149-151: truncated \UXXX
> X escape
> >>>
>

That says that there is some character in that line that is not valid
Unicode. Remove the line (and perhaps the ones above and below it at the
same time, in case it's around the line feed character(s)) and type it in
again. It's likely to be as easy as that.

-- 
André Engels, andreeng...@gmail.com
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Puzzled again

2011-08-02 Thread Richard D. Moores
On Tue, Aug 2, 2011 at 21:59, Dave Angel  wrote:

> When I paste that from your email into a file and run Python 2.7 on it, it
> behaves fine with no errors.  That's in Linux.

I should have said that I'm using Wing IDE Professional 4.0.3-1 (rev
24721), Windows Vista, and Python 3.2.1.

> But the easiest explanation is that you perhaps used a funny character for
> your triple-quotes.  And when you retyped them on a new line, you typed
> regular ones.
>
> For example, I've seen that sort of thing when someone wrote code in a
> Windows word processor that had "smart quotes."

No, no funny characters with Wing.

Thanks for your guess, Dave.

But here's a try using the regular command line:

C:\Windows\System32>python
Python 3.2.1 (default, Jul 10 2011, 20:02:51) [MSC v.1500 64 bit
(AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from mycalc import convertPath
Traceback (most recent call last):
  File "", line 1, in 
  File "C:\Python32\lib\site-packages\mycalc.py", line 36
"""
SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes
in position 149-151: truncated \UXXX
X escape
>>>

Dick
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python scripts into executable Windows programss

2011-08-02 Thread Christian Witts

On 2011/08/03 06:25 AM, Emeka wrote:

Hello All,

I would want to convert Python scripts into executable Windows 
programs. I have already checked out py2exe, it seems like they 
support only Python 2.5. Mine is Python 2.7.7. Could anyone here help 
me out on this issue?

?

Regards,
Emeka --
/Satajanus  Nig. Ltd


/


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


They do have support for Python 2.7, it's just the "latest version" on 
SF is listed as Py2.5 64bit.

http://sourceforge.net/projects/py2exe/files/py2exe/0.6.9/

--

Christian Witts
Python Developer

//
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] python Module for Windows Active Directory

2011-08-02 Thread Ajith Gopinath
Sure Tim. Thanks for your help.

Thanks and Regards
Ajith Gopinath



On Thu, Jul 28, 2011 at 8:32 PM, Tim Golden  wrote:

> On 28/07/2011 07:28, qbits...@gmail.com wrote:
>
>> Hi,
>>
>> Which is the best package/module in Python to work with Windows Active
>> Directory?
>>
>> I may need to create multiple OUs, set different users and computers and
>> fill their individual attributes. Later i may need to modify/delete and
>> then may need to check them for its availability.
>>
>
> You could try my active_directory module:
>
>  
> http://timgolden.me.uk/python/**active_directory.html
>
> although there's a much-improved version in development
> (and actively used here at work). If you're interested,
> look at:
>
>  
> http://svn.timgolden.me.uk/**active_directory/branches/**rework/
>
> TJG
> __**_
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/**mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Puzzled again

2011-08-02 Thread Dave Angel

On 08/02/2011 10:36 PM, Richard D. Moores wrote:

Puzzled again. Why the error. Line 36 is the line just above "import
os.path". I have many other functions in mycalc.py with examples
formatted exactly the same way.

def convertPath(path):
 """
 Given a path with backslashes, return that path with forward slashes.

 By Steven D'Aprano  07/31/2011 on Tutor list
 >>>  path = r'C:\Users\Dick\Desktop\Documents\Notes\College Notes.rtf'
 >>>  convertPath(path)
 'C:/Users/Dick/Desktop/Documents/Notes/College Notes.rtf'
 """
 import os.path
 separator = os.path.sep
 if separator != '/':
 path = path.replace(os.path.sep, '/')
 return path


from mycalc import convertPath

Traceback (most recent call last):
   File "", line 36, in
Syntax Error: """: c:\Python32\lib\site-packages\mycalc.py, line 36-1

def convertPath(path):
 """
 Given a path with backslashes, return that path with forward slashes.

 By Steven D'Aprano  07/31/2011 on Tutor list
 >>>  path = r'C:\Users\Dick\Desktop\Documents\Notes\College Notes.rtf'
 >>>  convertPath(path)
 'C:/Users/Dick/Desktop/Documents/Notes/College Notes.rtf'
 """
 import os.path
 separator = os.path.sep
 if separator != '/':
 path = path.replace(os.path.sep, '/')
When I paste that from your email into a file and run Python 2.7 on it, 
it behaves fine with no errors.  That's in Linux.


But the easiest explanation is that you perhaps used a funny character 
for your triple-quotes.  And when you retyped them on a new line, you 
typed regular ones.


For example, I've seen that sort of thing when someone wrote code in a 
Windows word processor that had "smart quotes."


--

DaveA

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Python scripts into executable Windows programss

2011-08-02 Thread Emeka
Hello All,

I would want to convert  Python scripts into executable Windows programs. I
have already checked out py2exe, it seems like they support only Python 2.5.
Mine is Python 2.7.7. Could anyone here help me out on this issue?
?

Regards,
Emeka --
*Satajanus  Nig. Ltd


*
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Indexing a list with nested tuples

2011-08-02 Thread bob gailer

On 8/2/2011 10:44 PM, Alexander Quest wrote:

Hi guys- I'm having a problem with a list that has nested tuples:

attributes = [("strength", 0), ("health  ", 0), ("wisdom  ", 0), 
("dexterity", 0)]


I've defined the list above with 4 items, each starting with a value 
of 0. The player
enters how many points he or she wants to add to a given item. The 
selection menu
is 1 - strength; 2 - health; 3 - wisdom; 4- dexterity. So the 
"selection" variable is actually
1 more than the index location of the intended item. So I have the 
following code:


print("Added ", points, "to ", attributes[selection-1][0], "attribute.")

My intent with this is to say that I've added this many points 
(however many) to the
corresponding item in the list. So if the player selects "1", then 
selection = 1, but I subtract
1 from that (selection -1) to get the index value of that item in the 
list (in this case 0). Then I
have [0] to indicate that I want to go to the second value within that 
first item, which is the
point value. I get an error saying that list indices must be integers, 
not strings. I get a similar

error even if I just put attributes[selection][0] without the minus 1.

Also, it seems that the tuple within the list cannot be modified 
directly, so I can't add points to the original value of "0" that all 
4 items start with. Is there a way to keep this nested list with
tuples but be able to modify the point count for each item, or will it 
be better to create a dictionary or 2 separate lists (1 for the names 
"Strength, Health, Wisdom, Dexterity" and one
for their starting values "0,0,0,0")? Any suggestions/help will be 
greatly appreciated!!!

Thanks for inquiring. Some guidelines about questions:

1 - show us more code. in this case specifically how you obtain user input.
2 - show the complete traceback

What does the error message tell you? Why would selection be a string 
rather than an integer? This has to do with how you obtain selection 
from the user. What


Why did you expect to be able to alter the value of a tuple element? 
Tuples are immutable! Use a list instead.


HTH

--
Bob Gailer
919-636-4239
Chapel Hill NC

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Indexing a list with nested tuples

2011-08-02 Thread Alexander Quest
Hi guys- I'm having a problem with a list that has nested tuples:

attributes = [("strength", 0), ("health  ", 0), ("wisdom  ", 0),
("dexterity", 0)]

I've defined the list above with 4 items, each starting with a value of 0.
The player
enters how many points he or she wants to add to a given item. The selection
menu
is 1 - strength; 2 - health; 3 - wisdom; 4- dexterity. So the "selection"
variable is actually
1 more than the index location of the intended item. So I have the following
code:

print("Added ", points, "to ", attributes[selection-1][0], "attribute.")

My intent with this is to say that I've added this many points (however
many) to the
corresponding item in the list. So if the player selects "1", then selection
= 1, but I subtract
1 from that (selection -1) to get the index value of that item in the list
(in this case 0). Then I
have [0] to indicate that I want to go to the second value within that first
item, which is the
point value. I get an error saying that list indices must be integers, not
strings. I get a similar
error even if I just put attributes[selection][0] without the minus 1.

Also, it seems that the tuple within the list cannot be modified directly,
so I can't add points to the original value of "0" that all 4 items start
with. Is there a way to keep this nested list with
tuples but be able to modify the point count for each item, or will it be
better to create a dictionary or 2 separate lists (1 for the names
"Strength, Health, Wisdom, Dexterity" and one
for their starting values "0,0,0,0")? Any suggestions/help will be greatly
appreciated!!!

-Alex
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Puzzled again

2011-08-02 Thread Richard D. Moores
Puzzled again. Why the error. Line 36 is the line just above "import
os.path". I have many other functions in mycalc.py with examples
formatted exactly the same way.

def convertPath(path):
    """
    Given a path with backslashes, return that path with forward slashes.

    By Steven D'Aprano  07/31/2011 on Tutor list
    >>> path = r'C:\Users\Dick\Desktop\Documents\Notes\College Notes.rtf'
    >>> convertPath(path)
    'C:/Users/Dick/Desktop/Documents/Notes/College Notes.rtf'
    """
    import os.path
    separator = os.path.sep
    if separator != '/':
        path = path.replace(os.path.sep, '/')
    return path

>>> from mycalc import convertPath
Traceback (most recent call last):
  File "", line 36, in 
Syntax Error: """: c:\Python32\lib\site-packages\mycalc.py, line 36-1
>>>

What solved the problem and what didn't:

This doesn't work:

def convertPath(path):
    """
    Given a path with backslashes, return that path with forward slashes.

    By Steven D'Aprano  07/31/2011 on Tutor list

    >>> path = r'C:\Users\Dick\Desktop\Documents\Notes\College Notes.rtf'
    >>> convertPath(path)
    #'C:/Users/Dick/Desktop/Documents/Notes/College Notes.rtf'
    """
    import os.path
    separator = os.path.sep
    if separator != '/':
        path = path.replace(os.path.sep, '/')
    return path

Nor this:

def convertPath(path):
    """
    Given a path with backslashes, return that path with forward slashes.

    By Steven D'Aprano  07/31/2011 on Tutor list

    #>>> path = r'C:\Users\Dick\Desktop\Documents\Notes\College Notes.rtf'
    #>>> convertPath(path)
    #'C:/Users/Dick/Desktop/Documents/Notes/College Notes.rtf'
    """
    import os.path
    separator = os.path.sep
    if separator != '/':
        path = path.replace(os.path.sep, '/')
    return path

But this does:

def convertPath(path):
    """
    Given a path with backslashes, return that path with forward slashes.

    By Steven D'Aprano  07/31/2011 on Tutor list
    """
    #>>> path = r'C:\Users\Dick\Desktop\Documents\Notes\College Notes.rtf'
    #>>> convertPath(path)
    #'C:/Users/Dick/Desktop/Documents/Notes/College Notes.rtf'
    import os.path
    separator = os.path.sep
    if separator != '/':
        path = path.replace(os.path.sep, '/')
    return path

Thanks,

Dick Moores
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] When to use def __init__ when making a class?

2011-08-02 Thread Steven D'Aprano

brandon w wrote:

I have two questions:

1)  When should I use "def __init__(self):" when I create a class?


Whenever you need something to happen when you create an instance.



2)  Would these two classes have the same effect?


Technically, no, but in practice, you would find it hard to see the 
difference for the example given. But for slightly different examples, 
the difference would be astonishing.





class Name:
def __init__(self):
man = Marcus
woman = Jasmine
return self.man, self.woman


Did you try the code before posting it?

Three problems with it:

(1) Firstly, Marcus and Jasmine are not built-in Python commands, so 
trying to execute man = Marcus raises NameError. You need to use 
quotation marks to turn it into a string.


(2) Fixing that problem, man = "Marcus" doesn't do what you expect 
either, because it creates a local variable man and not an attribute.


(3) Last but not least, the return result of __init__ is ignored, so 
even though you try to return self.man and self.women, nothing happens.


Also, calling the class "Name" is a bad idea, because it doesn't have 
anything to do with what the class actually holds, which is a *pair* of 
names, one male and one female.



This code should be written as:


class Couple:
def __init__(self):
self.man = "Marcus"
self.woman = "Jasmine"


This creates a class where every instance has its own independent 
attributes man and woman.




class Name:
man = Marcus
woman = Jasmine
return man, woman



Again, did you try this? If you did, you would discover it raises 
SyntaxError: you can't include a return statement inside a class, 
because it is meaningless.


SyntaxError: 'return' outside function

This should be written as

class Couple:
man = "Marcus"
woman = "Jasmine"


This creates a class where every instance shares the same pair of 
attributes.




In this example, the difference is not very great, because strings 
cannot be modified in place. If you try to store a new value for the 
attribute, Python defaults to creating an independent instance attribute 
rather than changing the shared class attribute.



Here is an example that may help show the difference:


class TestAttributes:
a = [1, 2, 3]  # Shared, and mutable.
def __init__(self):
self.b = [1, 2, 3]  # Not shared.


Now, using this:


>>> x = TestAttributes()  # Create a new instance.
>>> y = TestAttributes()  # And another one.
>>>
>>> x.a
[1, 2, 3]
>>> y.a
[1, 2, 3]
>>> x.a.append(42)  # Modify the SHARED list.
>>> y.a  # And all instances see the change!
[1, 2, 3, 42]
>>>
>>> x.b
[1, 2, 3]
>>> x.b.append(999)  # Modify the non-shared list.
>>> x.b
[1, 2, 3, 999]
>>> y.b  # Other instances are unchanged.
[1, 2, 3]





--
Steven

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] When to use def __init__ when making a class?

2011-08-02 Thread Brett Ritter
On Tue, Aug 2, 2011 at 8:47 PM, brandon w  wrote:
> 1)  When should I use "def __init__(self):" when I create a class?

When you have any initialization to do.  (in other words, when you
want class instantiation to do more than simply give you an instance
of the class.

> 2)  Would these two classes have the same effect?

Neither of these two classes compile.  You should try what you are
asking before asking, it will lead you to better questions.

Your examples show some misunderstanding about Python classes.

1)  an __init__ method shouldn't return anything.  The Class
construction call will already return an instance of the class,
__init__ is just about initialization.
2) A class definition likewise has no return value.
3) In your examples, Marcus and Jasmine are either intended to be
strings (and should be quoted), or are variables you didn't provide.

Here, try running these examples and see what you can figure out.
Experiment with them a little, then come back with questions on what
you observe.

class Name:
  def __init__(self):
self.man = "Marcus"
self.woman = "Jasmine"

instance = Name()
print instance.man  # Python 3 will use a different print syntax

class Name:
  pass

instance = Name()
instance.man = "Fred"
print instance.man

-- 
Brett Ritter / SwiftOne
swift...@swiftone.org
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] When to use def __init__ when making a class?

2011-08-02 Thread brandon w

I have two questions:

1)  When should I use "def __init__(self):" when I create a class?

2)  Would these two classes have the same effect?

class Name:
def __init__(self):
man = Marcus
woman = Jasmine
return self.man, self.woman



class Name:
man = Marcus
woman = Jasmine
return man, woman
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] python 2.3.4, how to use os.system and collect it's output to a file.

2011-08-02 Thread xDog Walker
On Tuesday 2011 August 02 08:40, Thirupathaiah Gande (tgande) wrote:
> Hi,
>
>
>
> I have Python 2.3.4.
>
> I want to use os.system command and collect a command's  output to a
> file. But it is not collecting all the output. It is truncating..
>
>
>
> Code is as below.
>
>
>
> cmd = "%s rl -comp %s@%s/%d  >> %s" % (C_CMD, i, branch, x,
> temp_acme_rl_log)
>
> cmd_res = os.system( cmd )
>
>
>
> What I am missing?
>

The stdlib has the commands module just for this sort of thing if your OS is 
Unix.

-- 
I have seen the future and I am not in it.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] python 2.3.4, how to use os.system and collect it's output to a file.

2011-08-02 Thread Alan Gauld

On 02/08/11 16:40, Thirupathaiah Gande (tgande) wrote:


I want to use os.system command and collect a command’s output to a
file. But it is not collecting all the output. It is truncating..


no its not truncating anything, it is returning the exit code of the 
command, because thats what os.system does.


You need to look at the Subprocess module to read/write to processes.
The documentation shows many examples of usage, but if you have specific 
problems come back here.


HTH,

Alan G.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] python 2.3.4, how to use os.system and collect it's output to a file.

2011-08-02 Thread Timo

On 02-08-11 17:40, Thirupathaiah Gande (tgande) wrote:


Hi,

I have Python 2.3.4.

Is there some reason for this? You probably should update to 2.7 if 
possible.


Then have a look at the Subprocess module documentation. There are some 
examples which should get you on the way.


Cheers,
Timo

I want to use os.system command and collect a command’s output to a 
file. But it is not collecting all the output. It is truncating..


Code is as below.

cmd = "%s rl -comp %s@%s/%d >> %s" % (C_CMD, i, branch, x, 
temp_acme_rl_log)


cmd_res = os.system( cmd )

What I am missing?

Thanks

gande


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] python 2.3.4, how to use os.system and collect it's output to a file.

2011-08-02 Thread Thirupathaiah Gande (tgande)
Hi,

 

I have Python 2.3.4. 

I want to use os.system command and collect a command's  output to a
file. But it is not collecting all the output. It is truncating..

 

Code is as below.

 

cmd = "%s rl -comp %s@%s/%d  >> %s" % (C_CMD, i, branch, x,
temp_acme_rl_log)

cmd_res = os.system( cmd )

 

What I am missing?

 

Thanks

gande

 

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Please code review.

2011-08-02 Thread Karim

On 08/02/2011 03:59 PM, Peter Otten wrote:

Karim wrote:


values = ( (22.5,21.5,121.5),
(5615.3,615.3,-615.3),
(-2315.7,315.7,415.7) )

it = _xrange_cellnames(rows=len(value), cols=len(values[0]))

table.getCellByName(it.next()).setValue(22.5)
table.getCellByName(it.next()).setValue(5615.3)
table.getCellByName(it.next()).setValue(-2315.7)

Some googling suggests that there exists a getCellByPosition() method. With
that the above would become (untested):

for x, column in enumerate(values):
 for y, value in enumerate(column):
 table.getCellByPosition(x, y).setValue(value)


Thanks for the tip I will check com.sun.star.text.TextTable API.

Regards
Karim
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Please code review.

2011-08-02 Thread Paul Kölle

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']





___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Please code review.

2011-08-02 Thread Karim


Thanks Martin,

This is the generator expression version.
I can use both function generator or generator expression version 
correction.


Cheers
Karim

On 08/02/2011 02:47 PM, Martin Gracik wrote:

def get_cellnames2(rows, cols):
rows = range(1, rows + 1)
cols = string.ascii_uppercase[:cols]
return ('%s%s' % (col, row) for row in rows for col in cols)


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Please code review.

2011-08-02 Thread 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.

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']


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor