473,804 Members | 1,999 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

beginner: using parameter in functions

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__.getQr yStr 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
class getQryStr:
def __init__(self,o p):
print op
self.x = 'd'
def returnStr(x,*ar gs):

print '%s %s me mad' % (x,args)
if x == 'd':
s = Template("delet e from columndef where tblid = $tblid and
colname = $colname")
else:
return 'nope' #this else is just for illustration and testing

d = dict(tblid=t.tb lid.getText(), colname=t.colNa me.getText())

print s.substitute(d)

return s

def delqry(self):

createfldobj = getQryStr('d')
s = createfldobj.re turnStr('d')
May 31 '06 #1
4 1337
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__.getQr yStr 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,o p):
print op
self.x = 'd'
def returnStr(self, *args):

print '%s %s me mad' % (self.x,args)
if self.x == 'd':
s = Template("delet e from columndef where tblid = $tblid and
colname = $colname")
else:
return 'nope' #this else is just for illustration and
testing

d = dict(tblid=t.tb lid.getText(), colname=t.colNa me.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.

Jun 1 '06 #2
On 1/06/2006 9:24 AM, 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__.getQr yStr instance at 0x01151D50> ('d',) me mad
Exactly right, first parameter is the object itself, second parameter is
a 1-tuple of the supplied args. See more explanation below.


(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.
No, 'd' is stored as the value of the attribute you've named "x". One of
the main points of the whole OO caper is that objects have attributes --
please see later remarks about the tutorial.

so basically the function returns nope as it stands

python is sure different from other languages i have used.

thanks for any help,
jim
class getQryStr:
def __init__(self,o p):
print op
self.x = 'd'
You probably meant
self.x = op
def returnStr(x,*ar gs):
Like the first (__init__) method, this should have the mandatory "self"
argument, plus *one* other arg .. *if* you need it. It's not apparent
why you are calling the constructor *and* the returnStr method *each*
with 'd'.


print '%s %s me mad' % (x,args)
if x == 'd':


Here x is the object that you have created. The first argument to a
method is the object itself, and is conventionally named "self". It must
be declared in the method itself
def amethod(self, arg1, arg2):
but is supplied automatically when you invoke it
anobj.amethod(' foo', 42)

[snip]

Please consider working your way through the Python tutorial
http://docs.python.org/tut/node11.html
and/or one of the free e-books e.g.
http://www.byteofpython.info/

At the end of this post is a modified version of your script which shows
what is going on under normal expected usage.

HTH,
John

8<=== demo script ===

C:\junk>type use_self.py
class getQryStr:

def __init__(self, op):
print '__init__ ... op:%r' % op
self.x = op

def returnStr(self, arg):
print 'returnStr ... self.x:%r arg:%r' % (self.x, arg)
return '=%s=%s=' % (self.x, arg)

obj = getQryStr('blah ')
print '__main__ ... obj.x:%r' % obj.x
s = obj.returnStr(' yadda')
print '__main__ ... s:%r' % s

8<=== output from demo script ===

C:\junk>use_sel f.py
__init__ ... op:'blah'
__main__ ... obj.x:'blah'
returnStr ... self.x:'blah' arg:'yadda'
__main__ ... s:'=blah=yadda= '
8<=== end ===
Jun 1 '06 #3
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" <jm********@vel seis.com.au> wrote in message
news:ma******** *************** *************** *@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__.getQr yStr 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,o p):
print op
self.x = 'd'
def returnStr(self, *args):

print '%s %s me mad' % (self.x,args)
if self.x == 'd':
s = Template("delet e from columndef where tblid = $tblid and
colname = $colname")
else:
return 'nope' #this else is just for illustration and
testing

d = dict(tblid=t.tb lid.getText(), colname=t.colNa me.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.

Jun 1 '06 #4

"John Machin" <sj******@lexic on.net> wrote in message
news:44******@n ews.eftel.com.. .

thanks for the help.
it is really appreciated.

i am going to do some more reading in the next couple of days.
jim
Jun 1 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

46
3534
by: J.R. | last post by:
Hi folks, The python can only support passing value in function call (right?), I'm wondering how to effectively pass a large parameter, such as a large list or dictionary? It could achieved by pointer in C++, is there such way in Python? Thansk in advance. J.R.
0
6707
by: Nashat Wanly | last post by:
HOW TO: Call a Parameterized Stored Procedure by Using ADO.NET and Visual C# .NET View products that this article applies to. This article was previously published under Q310070 For a Microsoft Visual Basic .NET version of this article, see 308049. For a Microsoft Visual C++ .NET version of this article, see 310071. For a Microsoft Visual J# .NET version of this article, see 320627. This article refers to the following Microsoft .NET...
15
2016
by: Pelle Beckman | last post by:
Hi all, I have a few newbie questions: In function declaration what does a 'const' mean inside the parameter list ? That it won't modify the value? void MemberFunction(const int x);
39
2427
by: TonyJeffs | last post by:
Great book - I like the way that unlike other books, AC++ explains as much as possible about every piece of code discussed, so I'm not left thinking, "well...OK... I get line 12, but I wonder what the rest of it means...". Still, I have some questions, that are frustrating me:- Grateful for any comments. 1. What is the difference between #include <iostream> // (or any include file) which is used in this
4
3844
by: sam1967 | last post by:
How do I get a function to return a GMP integer type mpz_t when i try it i get an error message. i am trying mpz_t hooch (int x) { mpz_t y; ........
3
1442
by: gruzdnev | last post by:
Hi all, I've started to program in C not long ago, and I've got some questions: (I work on Linux 2.4.22/Debian) 1. Why the "**var" construct is used? What are the cases when it is commonly needed? I'd like to read more about it, but there's nothing in K&R on this theme, AFAIR. 2. Suppose, I want to see the source code of the "fopen" function used
1
2628
by: Mike Malter | last post by:
I am just starting to work with reflection and I want to create a log that saves relevant information if a method call fails so I can call that method again later using reflection. I am experimenting a bit with what I need to do this and have the following code snippet. But first if I pass the assembly name and type to Activator.CreateInstance() it always fails. However if I walk my assembly and get a type value, the call to...
18
2929
by: mitchellpal | last post by:
Hi guys, am learning c as a beginner language and am finding it rough especially with pointers and data files. What do you think, am i being too pessimistic or thats how it happens for a beginner? Are there better languages than c for a beginner? For instance visual basic or i should just keep the confidence of improving?
22
18154
by: ddg_linux | last post by:
I have been reading about and doing a lot of php code examples from books but now I find myself wanting to do something practical with some of the skills that I have learned. I am a beginner php programmer and looking for a starting point in regards to practical projects to work on. What are some projects that beginner programmers usually start with? Please list a few that would be good for a beginner PHP programmer to
0
10343
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10331
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10087
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9166
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7631
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5667
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4306
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3831
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3001
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.