Skip to content

Instantly share code, notes, and snippets.

@mbaltrusitis
Last active February 1, 2016 21:14
Show Gist options
  • Save mbaltrusitis/0216c6568af1fdf521f1 to your computer and use it in GitHub Desktop.
Save mbaltrusitis/0216c6568af1fdf521f1 to your computer and use it in GitHub Desktop.
Keep running a method until I have enough arguments.
#!/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