Created
March 3, 2016 00:22
-
-
Save maatthc/9b5e5fcb8aba5c3a5c92 to your computer and use it in GitHub Desktop.
Testing on run time how many parameters a function is expecting.
This file contains 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
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