From: Tim Johnson on
On 2009-10-31, Steven D'Aprano <steve(a)REMOVE-THIS-cybersource.com.au> wrote:
>>> Idiomatic Python is to use CamelCase for classes.
>> Can you point me to a discussion on Idiomatic Python, CamelCase and
>> other matters?
>
<...> See PEP 8:
>
> http://www.python.org/dev/peps/pep-0008/
Got it. Thanks.
>
>>> invalid parameter shouldn't raise the same error as failing an
>>> attribute look-up. That's misleading and confusing.
>>
>> What error class or other approach do you recommend?
>
> Unless you have a good reason for doing something different, do what
> Python built-ins do:
>
>>>> int('123', parrot=16)
> Traceback (most recent call last):
> File "<stdin>", line 1, in <module>
> TypeError: 'parrot' is an invalid keyword argument for this function
Understood. I kyped that method from from an open source library module
and have been using it ever since.
>
>>> I also should point out that your trick will fail if you are using
>>> __slots__.
>> ??. Will research that. Elaborate if you wish.
>
> __slots__ are an optimization for making objects smaller than normal if
> you have many millions of them:
>
> http://docs.python.org/reference/datamodel.html#slots
Thanks.
<....>
>
>> If the class grows - and I expect it will - I'd prefer to stick with
>> the keywords approach. That approach also allows me to use a
>> dictionary to initialize the object.
>
> You can still do that with named parameters.
>
<...>
>>>> class Parrot:
> ... def __init__(self, name='Polly', colour='blue',

>>>> p = Parrot("Sparky", 'white', "Cockatoo")
>>>> data = dict(colour='red', name='Fred', foo=1)
>>>> p = Parrot(**data) # raise an error with bad input
> Traceback (most recent call last):
> File "<stdin>", line 1, in <module>
> TypeError: __init__() got an unexpected keyword argument 'foo'
<...> OK. That makes sense. You have made a believer of me.

I really appreciate all the time you have taken with this.
Many programmers I know stay away from 'lists' such as this, because
they are afraid to show their ignorance. Me, I'm fearless, and I have
learned a lot that I might not have otherwise.

take care
--
Tim
tim(a)johnsons-web.com
http://www.akwebsoft.com
From: MRAB on
Hendrik van Rooyen wrote:
> On Friday, 30 October 2009 17:28:47 MRAB wrote:
>
>> Wouldn't it be clearer if they were called dromedaryCase and
>> BactrianCase? :-)
>
> Ogden Nash:
>
> The Camel has a single hump-
> The Dromedary, two;
> Or the other way around-
> I'm never sure. - Are You?
>
If you make the first letter a capital:

Dromedary starts with "D", 1 bump, 1 hump.

Bactrian starts with "B", 2 bumps, 2 humps.
From: Steven D'Aprano on
On Sat, 31 Oct 2009 11:15:48 -0500, Tim Johnson wrote:

> Many programmers I know stay away from 'lists' such as this, because
> they are afraid to show their ignorance. Me, I'm fearless, and I have
> learned a lot that I might not have otherwise.

The only stupid question is the one you are afraid to ask.

Good luck!


--
Steven
From: Aahz on
In article <02fd0c85$0$1326$c3e8da3(a)news.astraweb.com>,
Steven D'Aprano <steve(a)REMOVE-THIS-cybersource.com.au> wrote:
>On Sat, 31 Oct 2009 11:15:48 -0500, Tim Johnson wrote:
>>
>> Many programmers I know stay away from 'lists' such as this, because
>> they are afraid to show their ignorance. Me, I'm fearless, and I have
>> learned a lot that I might not have otherwise.
>
>The only stupid question is the one you are afraid to ask.

"There are no stupid questions, only stupid people."
--
Aahz (aahz(a)pythoncraft.com) <*> http://www.pythoncraft.com/

[on old computer technologies and programmers] "Fancy tail fins on a
brand new '59 Cadillac didn't mean throwing out a whole generation of
mechanics who started with model As." --Andrew Dalke
From: Ben Finney on
aahz(a)pythoncraft.com (Aahz) writes:

> "There are no stupid questions, only stupid people."

The earliest source I know for that aphorism is the fictional teacher
Mister Garrisson, from South Park. Can anyone source it earlier?

--
\ “Read not to contradict and confute, nor to believe and take |
`\ for granted … but to weigh and consider.” —Francis Bacon |
_o__) |
Ben Finney