Is it possible to get string from function?

Roy Smith roy at panix.com
Thu Jan 16 00:40:39 EST 2014


In article <mailman.5570.1389849928.18130.python-list at python.org>,
 Chris Angelico <rosuav at gmail.com> wrote:

> On Thu, Jan 16, 2014 at 2:46 PM, Roy Smith <roy at panix.com> wrote:
> > So, I figured I would write a meta-test, which used introspection to
> > find all the methods in the class, extract the strings from them (they
> > are all assigned to a variable named RECEIPT), and check to make sure
> > they're all different.
>> [...]
> But you might be able to shortcut it enormously. You say the strings
> are "about 2500 characters long, hex-encoded". What are the chances of
> having another constant, somewhere in the test function, that also
> happens to be roughly that long and hex-encoded?

The chances are exactly zero.

> If the answer is "practically zero", then skip the code, skip 
> co_names, and just look through co_consts.

That sounds like it should work, thanks!

> Of course, this whole theory goes out the
> window if your test functions can reference another test's RECEIPT;

No, they don't do that.



More information about the Python-list mailing list