The following does exactly what you want. It starts by initializing the list AV to all NULL, then iterates of the number of arguments supplied, and replaces them appropriately to form the query string that you wanted. The SQL =
string adds quotes to the first argument only. Did I understand correctly what you were trying to do?
def execSp(*args):
AV = []
SQL = "exec SP_TEST(";
for ii in range(0,4) :
AV.append("NULL");
ii = 0;
for a in args:
AV[ii] = str(a);
ii+=1;
SQL = SQL + "\'" + AV[0] + "\'," + AV[1] + "," + AV[2] + "," + AV[3] + ")";
print SQL
execSp("hello", 1, 2, 3);
execSp("hi", 2, 3);
When I run this, I get
exec SP_TEST('hello',1,2,3)
exec SP_TEST('hi',2,3,NULL)