Most efficient way to write data out to a text file?

Steve Holden sholden at holdenweb.com
Mon Jul 1 10:34:31 EDT 2002


"Bengt Richter" <bokr at oz.net> wrote in message
news:afl9d1$5k0$0 at 216.39.172.122...
> On Sat, 29 Jun 2002 19:05:18 GMT, "Fredrik Lundh" <fredrik at pythonware.com>
wrote:
>
> >Dave Kuhlman wrote:
> >
> [...]
> >> Is finding things in globals slower than finding them in locals?
> >
> >yes.  Python assigns integer indices to local names, and
> >stores the corresponding objects in an array.
> >
> Is this done for built-in keywords also? ISTM a standard list
> of indices could be defined for a particular Python version,
> and code generated to take advantage.
>
I'm not sure this would help as much as you think, given that before a
built-in is used the interpreter must check that it isn't a module-global
name. Try

>>> None = "hello"
>>> print __builtins__.None
None
>>> print None
hello
>>> del None
>>> print None
None
>>> del __builtins__.None # now you're hosed...
>>> print None
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
NameError: name 'None' is not defined
>>>

[...function call optimization...]

>
> If necessary to make it unambiguous and to make compilation easier, you
could have
> a "builtin" declaration analogous to "global." Or the usage might be
popular enough
> that you'd want a way to opt out instead of opt in. Since it's a bad idea
to rebind
> keywords anyway, maybe backwards compatibility wouldn't be too much of a
problem if
> it were default for some builtins functions in a future version?
>
There seems to be quite a lot of resistance to making such builtins
non-overridable. I suspect this is to do with wanting to retain as much
intropsection capaibility as possible.

> Hm, seems like you could do static arg count checks too for this kind of
builtin use.
>
> Hm2, wonder if you could allow user-defined assignment of functions to
dynamically
> assigned byte codes within a user range using "builtin user_func"
declarations,
> so that compilation would make analogous code like that suggested for real
builtins.
>
> OTTOMH just now, not exactly PEP-ready ;-)
>
Well, even if less than half-baked, at least considering some of the
problems you would actually encounter. Not sure this would be my first
choice for optimization when we don't even use constant-folding yet!

regards
-----------------------------------------------------------------------
Steve Holden                                 http://www.holdenweb.com/
Python Web Programming                http://pydish.holdenweb.com/pwp/
-----------------------------------------------------------------------








More information about the Python-list mailing list