The Cost of Dynamism (was Re: Pyhon 2.x or 3.x, which is faster?)

Random832 random832 at fastmail.com
Wed Mar 23 20:12:12 EDT 2016


On Wed, Mar 23, 2016, at 19:55, Steven D'Aprano wrote:
>         while psource:
>                 c, psource = psource[0], psource[1:]
>                 lxsymbol = disptable[min(ord(c), 256)](c, psource)
> 
> 
> But one positive: this conclusively proves that "Pythonic" is in the eye
> of
> the beholder. Dennis thinks that c, psource = psource[0], psource[1:] is
> reasonable Python code; you think it's not ("I'm not sure why [Bart]
> thinks
> this is pythonic").

I guess the question is, what do you _actually_ need the tail string
for? If you're using it in a loop, to pop further characters from (the
scenario that would cause it to be copying the string over lots of
times), wouldn't it make more sense to use a StringIO (or, in the real
world where your C source code isn't a string, a file) and let that
class take care of handing out characters when you ask for them?

Like...

fsource = StringIO(psource)

while True:
    c = fsource.read(1)
    lxsymbol = disptable[min(ord(c), 256)](c, fsource)



More information about the Python-list mailing list