Last active
February 1, 2016 21:14
-
-
Save mbaltrusitis/0216c6568af1fdf521f1 to your computer and use it in GitHub Desktop.
Keep running a method until I have enough arguments.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/local/bin/python3 | |
import inspect | |
import random | |
class Foo(object): | |
def a_method(self, x, y, z): | |
print('Your method ran:\n', x, y, z) | |
if __name__ == '__main__': | |
a_class = Foo() | |
args = [] | |
kwds = {} | |
while True: | |
try: | |
a_class.a_method(*args, **kwds) | |
break | |
except TypeError: | |
your_params = inspect.getargspec(a_class.a_method).args | |
args.extend([random.randint(1, 100) for x | |
in range(0, (len(your_params)-1))]) # ignore the `self` of the method | |
print('Your params are:\n{}'.format(your_params)) | |
continue |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment