0

I have created the following variable, which captures the function from a Point object I created:

j = i.getfunction()
print(j)

The print(j) outputs something like this whenever it's called:

<function draw_H at 0x1057ce268>

What I want to do is find out if the item attached to the variable contains certain words. For instance, using the print(j) output above, I want to find out if j contains draw_H, like so:

if j contains draw_H:
    # Run this code

How would I do this? Specifically, how would I find out if an item attached to a variable contains a certain word? Any help is greatly appreciated!

5
  • draw_H is not value. Function <function draw_H at 0x1057ce268> is value attached to variable. draw_H is name of function attached to variable. Commented Jan 21, 2016 at 22:45
  • @furas So, how would I capture the name of the function? Commented Jan 21, 2016 at 22:48
  • 1
    someone already shows solution - j.__name__ == "draw_H" Commented Jan 21, 2016 at 22:48
  • @furas Yeah, he deleted his comment, and I did not clearly see what he wrote. I'll try that. Commented Jan 21, 2016 at 22:49
  • 1
    or if "draw_H" in j.__name__:. j.__name__ is a string so you can use other string functions. Commented Jan 21, 2016 at 22:50

1 Answer 1

1

Use the __name__ attribute:

print (j.__name__)

to test for a substring do:

if "draw_H" in j.__name__:
    <do stuff>
Sign up to request clarification or add additional context in comments.

1 Comment

Yup, that worked. Thanks!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.