Coding standard: Prefixing variables to indicate datatype

Simon Burton simonb at webone.com.au
Thu Jan 16 19:18:32 EST 2003


On Thu, 16 Jan 2003 13:31:48 +0000, John Machin wrote:

> "Simon Burton" <simonb at webone.com.au> wrote in message news:<pan.2003.01.16.09.42.41.751206 at webone.com.au>...

>> Just wrote this:
>> 
>> def capit(s):
>>   l = s.split("_") # could re-use s here
>>   l = [ s.capitalize() for s in l ]
>>   return string.join(l,"")
>> 
>> capit("some_name") returns "SomeName"
>> 
>> regards,
>> Simon Burton.
> 
> 1. What is the point of reusing variable names when the function could
> be a one-liner and still quite legible:
> 
> def capit(s):
>    return "".join([x.capitalize() for x in s.split("_")])

my version i can change (eg. comment out a line); all the bits are exposed.

> 
> 2. string.join()???? Are you still using Python 1.5???? Update now!!!!

oh my "".join seems a bit strange; i guess i'll get used to it - glad i
don't have to import string anymore :)

> 
> 3. Can you see what is wrong with this without feeding it to Python:
> 
>   def capit(s):
>     l = s.split("_") # could re-use s here
>     l = [ s.capitalize() for s in 1 ]
>     return string.join(l,"")

Nope.

> 
> 4. Have you considered that capit() conflates "fubar", "_fubar",
> "__fubar", etc?

OK, only needed it for these_things_in_the_middle_names.
Hmm, I did think about extending capwords to take a separator argument (eg.
"_") in which case, yes "_fubar"->"_Fubar" but , blah, Who_Wants_This_Anyway?

Thanks for the tips,

Simon Burton.






More information about the Python-list mailing list