beginner: using parameter in functions
John McMonagle
jmcmonagle at velseis.com.au
Wed May 31 19:57:13 EDT 2006
On Wed, 2006-05-31 at 23:24 +0000, 3rdshiftcoder wrote:
> hi-
>
> i am having trouble using parameter values in my function and to be honest a
> little trouble with
> member variables. i am trying to pass in the argument 'd' representing
> delete.
> what the code will do is if it is 'd' it will make a delete query template
> string.
> if it is an 'i' then insert query etc.
>
> this is the results of my attempt to print the contents of the parameter
> values.
> <__main__.getQryStr instance at 0x01151D50> ('d',) me mad
>
>
> (and on a side note if i dont include the *args i get an invalid number of
> parameters supplied message.)
> why is it returning the value in this format ('d',) ?
> i cant get x == d
> i guess that value 'd' is stored in a tuple and i'd like to get it out of
> there.
>
> so basically the function returns nope as it stands
>
> python is sure different from other languages i have used.
>
> thanks for any help,
> jim
>
Try, the following:
class getQryStr:
def __init__(self,op):
print op
self.x = 'd'
def returnStr(self, *args):
print '%s %s me mad' % (self.x,args)
if self.x == 'd':
s = Template("delete from columndef where tblid = $tblid and
colname = $colname")
else:
return 'nope' #this else is just for illustration and
testing
d = dict(tblid=t.tblid.getText(), colname=t.colName.getText())
print s.substitute(d)
return s
Regards,
John
--
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.
More information about the Python-list
mailing list