[Tutor] compare two souce files
Steven D'Aprano
steve at pearwood.info
Thu Oct 28 13:22:25 CEST 2010
Jojo Mwebaze wrote:
> Hello Tutor
>
> I would like to compare two souce code files but ignoring doc strings,
> comments and space (and perharps in future statement by statement
> comparision)
>
> e.g
>
> class Foo
> def foo():
> # prints my name
> return 'my name'
>
> class Boo
> def boo():
> print 'my name'
>
> Want to check if Foo and Boo are the same. At functional level one can use
>
> boo.func_code.co_code == foo.func_code.co_code
>
> What is the class level equivlant of this?
Foo.foo.func_code.co_code == Boo.boo.func_code.co_code
To check if the classes are equivalent, something like this will get you
started:
if dir(Foo) == dir(Boo):
for attr in dir(Foo):
if getattr(Foo, attr) != getattr(Boo, attr):
print "Unequal"
break
--
Steven
More information about the Tutor
mailing list