Arg names in class and function code - Newbie question
Joe Green
the_3_project at yahoo.com
Tue Apr 29 01:41:40 EDT 2003
newspost at lolmc.com (Lol) wrote in message news:<64e13ba5.0304281424.52cb6b5d at posting.google.com>...
> HI all,
> Could anyone let me know - do the names you give as arguments HAVE to be
> actual variable names?
> e.g def readFile(filename,dir):
> blah blah
> return blah
> or even class FileRead(filename,dir):
> def doSomething (self,this):
> yadda yadda
> return yadda
>
> In the above examples do filename and dir have to be the name of the
> variables to pass as args to the class/functions OR are they descriptive
> so I can pass the real name of the file and directory?
No, they don't. However, if you are using default values, then they
do.
For example:
def myfunc(arg1=None, arg2=None)
Here, if you are calling 'myfunc' and passing it any arguments, you
must call them by name. e.g.
myfunc(arg1='hi', arg2='hello')
Otherwise the interpreter will have no idea what value goes to what
(the order by which you pass the arguments doesn't matter).
If you only have something like:
def myfunc(arg1, arg2)
then you don't have to explitly call them anything, you can do
s1 = 'hi'
s2 = 'hello'
myfunc(s1,s2)
and that should work fine. Experiment on your python shell.
Hope that helps.
More information about the Python-list
mailing list