__str__ vs. __repr__

Phil Hunt philh at vision25.demon.co.uk
Tue Nov 16 02:57:23 CET 1999


In article <m3n1shp2uu.fsf at atrus.jesus.cam.ac.uk>
           mwh21 at cam.ac.uk "Michael Hudson" writes:
> philh at vision25.demon.co.uk (Phil Hunt) writes:
> 
> > In article <01fd01bf2dce$d2c03cf0$f29b12c2 at secret.pythonware.com>
> >            fredrik at pythonware.com "Fredrik Lundh" writes:
> > > 2) what's the reason byte code cannot be used to recover
> > > the original source code
> > 
> > Perhaps because two different (but obviously functionally
> > identical and very similar) source codes could produce the same
> > byte code.
> 
> I doubt it actually. Python's bytecode is really pretty high
> level. Leastaways, I can't think of any examples.

How about:

   x = a + b + c
   x = (a + b) + c
   x=a+b+c

I'd guess these all produce the same bytecode.

I'd also not be surprised if you could consistently change the
name of a local variable within a function without changing bytecodes,
i.e. Python internally doesn't know the names of local variables.

> It's one of those things I might get round to writing one of these
> days. I don't really know how hard it would be. Not especially, I
> suspect.

You might want to have a look at how Java bytecode decompilers
work.

-- 
Phil Hunt - - - - - - - - -  philh at vision25.demon.co.uk
Moore's Law: processor speed doubles every 18 months
Gates' Law: software speed halves every 18 months





More information about the Python-list mailing list