beginner: using parameter in functions

3rdshiftcoder go at away.com
Wed May 31 20:34:35 EDT 2006


thanks very much John!

so i can have self as function parameter as well as in a method.
that allowed me to use properties to retrieve the value set in the 
constructor.
i just changed the function return statement and it worked.
i was working along these lines but couldnt get it up and running as
fast as you posted.

templating sure is a great way to create dynamic query strings.

very cool so far but still lots to learn.

thanks again,
jim


"John McMonagle" <jmcmonagle at velseis.com.au> wrote in message 
news:mailman.6388.1149119924.27775.python-list at python.org...
> 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