output question 1
Simon Brunning
simon.brunning at gmail.com
Thu Nov 10 05:48:34 EST 2005
On 10/11/05, leewang kim <leewang.kim at gmail.com> wrote:
> I wrote the following code and got the output:
> a 13 0
> None
> b 81 3
(snip)
> where are those 'none' from? and how can I remove them?
>
> class Point:
> def __init__(self,x,y,name):
> self.x = x
> self.y = y
> self.name = name
> def summary(self):
> print self.name,self.x,self.y
Here you print your self.name value etc.
> if __name__ == '__main__':
> from string import letters
> m = 13,81,8,9,1
> n = 0,3,2,2,1
> q=len(x)
> points = [ Point(m[i],n[i],letters[i]) for i in range(q) ]
> i=0
> while i<q:
> print points[i].summary()
Here you print whatever is returned from the summary() method. Since
that method doesn't return anything explicitly, None is returned by
default, and you are printing that.
> i=i+1
One simple fix - change the summary method to returnt the values
rather than print them - replace 'print' with 'return' in that method.
Another would be not to print the returned values - remove 'print'
from your while loop.
--
Cheers,
Simon B,
simon at brunningonline.net,
http://www.brunningonline.net/simon/blog/
More information about the Python-list
mailing list