From: Philip Semanchuk on

On Jan 11, 2010, at 2:50 PM, Phlip wrote:

> MRAB wrote:
>
>> Scott wrote:
>
>>> for prtnmS in open(portfpth):
>>> prtnmS = prtnmS.rstrip()
>
>> There's nothing wrong with building dicts or other lookup tables
>> outside
>> a function in order to avoid re-creating them every time the
>> function is
>> called.
>
> However, please consider writing complete, pronounceable names for
> variables. This looks like Fortran!


Wht doYu mn? I thnk hisCde is ez2rd!





From: Scott on
On Jan 11, 1:50 pm, Phlip <phlip2...(a)gmail.com> wrote:
> MRAB wrote:
> > Scott wrote:
> >> for prtnmS in open(portfpth):
> >>     prtnmS = prtnmS.rstrip()
> > There's nothing wrong with building dicts or other lookup tables outside
> > a function in order to avoid re-creating them every time the function is
> > called.
>
> However, please consider writing complete, pronounceable names for variables.
> This looks like Fortran!

Thanks for the advice.
Scott
Chrmn, Scty fr th lmntn f vwls
From: Steven D'Aprano on
On Mon, 11 Jan 2010 18:57:09 +0000, MRAB wrote:

> There's nothing wrong with building dicts or other lookup tables outside
> a function in order to avoid re-creating them every time the function is
> called.

Actually there is, but the benefit (avoiding the re-creation of the
table) may be worth the cost (loss of encapsulation due to the use of a
global variable).

Also, it is slightly slower to access a global than to access a local.
This truly is a micro-optimization, and won't matter one bit for most
functions, but in some rare cases it may.

But these are just quibbles. In general, I would agree with you.


--
Steven
From: Scott on
> There's nothing wrong with building dicts or other lookup tables outside
> a function in order to avoid re-creating them every time the function is
> called.

Brilliant! I didn't think of that. I guess I accidentally did it right
this time as I query that dictionary quite a few times from the
function.

Thanks MRAB and All!