beginner, idomatic python 2
bambam
david at asdf.asdf
Fri Aug 24 04:31:43 EDT 2007
> trying to be "idiomatic"
...I hope that if a python programmer looks at my code it
won't be an excuse to discard it. Less of an issue with Python
than with C/C++, but since I'm just starting...
def device(DeviceType):
if DeviceType=='PSP':
return Psp()
elif DeviceType=="Power Supply"
return Pwr()
What about the parameter "DeviceType"?
Also, I see what you mean now, DEVICE_DICT is upper
case because it is a 'constant' -- I'd missed that point.
Steve.
"Bruno Desthuilliers" <bruno.42.desthuilliers at wtf.websiteburo.oops.com>
wrote in message news:46ce8d0c$0$410$426a74cc at news.free.fr...
> bambam a écrit :
>> Would someone like to suggest a replacement for this? This is a
>> function that returns different kinds of similar objects, depending
>> on what is asked for. PSP and PWR are classes. I don't really
>> want to re-write the calling code very much: I'm just wondering
>> if the function can be replaced with some kind of OOP pattern.
>
> Dan already answered to this. Just as a side note, and since you're trying
> to be "idiomatic", Python's naming convention is to use all_lower for
> functions, MixedCaps for classes (except - mostly for historical reasons -
> the builtin types...), and ALL_LOWER for symbolic (pseudo) constants.
>
>
>> def Device(DeviceType):
>> if DeviceType=='PSP':
>> return PSP()
>> elif DeviceType=="Power Supply"
>> return PWR()
>> etc...
>>
>>
>> Thanks!
More information about the Python-list
mailing list