[Tutor] variables within function - wha?

Simon Brunning SBrunning@trisystems.co.uk
Thu, 19 Jul 2001 16:12:39 +0100


> From:	kromag@nsacom.net [SMTP:kromag@nsacom.net]
> def filter(cc,rpm,type):
> 	cid=cc/16.387
> 	ocg=(cid*rpm)/20839
> 	foam=ocg*1.3767
> 	paper=ocg*1.2181
> 	if type==paper:
> 		return paper,
> 	elif type==foam:
> 		return foam,
> 	else:
> 		return ocg
 
You might want to replace lines 6 thru 9 with:

    if type=='paper':
        return paper
    elif type=='foam':
        return foam

BTW, are you using tabs to indent your code? Don't! Use spaces instead.
 
> I can't figure out why:
> 
> >>> filter(1800,7000,foam)
> Traceback (innermost last):
>   File "<pyshell#1>", line 1, in ?
>     filter(1800,7000,foam)
> NameError: There is no variable named 'foam'
> >>> 
> 
> occours. Have I been inhaling too much brake cleaner?
 
Try:

filter(1800,7000,'foam')

and it should work.

BTW, filter is a bad name for this function, because there is already a
built-in with that name.

Cheers,
Simon Brunning
TriSystems Ltd.
sbrunning@trisystems.co.uk





-----------------------------------------------------------------------
The information in this email is confidential and may be legally privileged.
It is intended solely for the addressee. Access to this email by anyone else
is unauthorised. If you are not the intended recipient, any disclosure,
copying, distribution, or any action taken or omitted to be taken in
reliance on it, is prohibited and may be unlawful. TriSystems Ltd. cannot
accept liability for statements made which are clearly the senders own.