Skip to content

Instantly share code, notes, and snippets.

@maatthc
Created March 3, 2016 00:22
Show Gist options
  • Save maatthc/9b5e5fcb8aba5c3a5c92 to your computer and use it in GitHub Desktop.
Save maatthc/9b5e5fcb8aba5c3a5c92 to your computer and use it in GitHub Desktop.
Testing on run time how many parameters a function is expecting.
from inspect import getargspec;
import sys
class Consumer(object):
def __init__(self, path, callback):
print("Creating class..")
self._path = path
self._callback = callback
def use(self):
print("Using Class...")
# Decide if use one or two parameters
(myargs, varargs, keywords, defaults) = getargspec(self._callback)
print(len(myargs))
def one_param(first):
print(first)
def two_param(first,second):
print("%s - %s" %(first, second))
if __name__ == '__main__':
one_param("Testing func...")
print("Using %s as Func.." % two_param)
print("Using %s as Func.." % one_param)
con = Consumer("/va/log/messages",two_param).use()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment