On 13/05/2006 1:55 AM, vbgunz wrote:
> I forgot to explain my reason for over shadowing the 'string' built-in
> within my iterator. To me, it doesn't matter because the string
> identifier is temporary within the function and dies when the function
> dies. Also, I personally don't use the string function and prefer
> ''.join('hi'), etc. Also, at least for me just starting out in Python,
> I find 'string' to be as readable as possible :)
> 
> what do you think about that?
> 

1. 'string' is not a function, it is a module. I'm glad you don't use 
the non-existent 'string function'.

2.

 >>> ''.join('hi')
'hi'

You prefer to do that instead of what?

Look at the docs on the .join() method carefully, and consider the 
following:
 >>> '-'.join('hello')
'h-e-l-l-o'
 >>>

3. Back to the shadowing thing:

'string' is admittedly not a good example to pull you up on, as that 
module is little used these days. However it is the thin end of the 
wedge, and your adding 'index' in round 2 just drove the wedge in a 
little further. Once you start using words like 'file' and 'list' as 
variable names, your code will be almost as *UN*readable as possible. 
It's not just the shadowing possibility, it's the confusion in the 
reader's mind between the usual/normal Python meaning of a word and the 
meaning that you have attached to it. As you are just starting out in 
Python, now is the time to acquire good habits.

Cheers,
John
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to