* I meant that*: A method actually can be called from the command prompt, but the syntax is quite different than that used to call a function from the command prompt.
On Fri, Jan 14, 2011 at 2:37 PM, Ben Ganzfried <ben.ganzfr...@gmail.com>wrote: > I actually just figured it out (since the tutorial talks about the > difference in indentation between a method and a function in a later > chapter). Basically, a method is within a class and therefore cannot be > called from the command prompt whereas a function that stands by itself in a > script can be called from the command prompt. > > Although if this isn't quite right or there's more to it, I would still > definitely appreciate any advice you have. > > Thanks again, > > Ben > > > On Fri, Jan 14, 2011 at 1:53 PM, Ben Ganzfried <ben.ganzfr...@gmail.com>wrote: > >> Hey guys, >> >> I'm using a tutorial geared for a 2.x version of Python and I am currently >> using Python 3.1-- so it is possible that my confusion has to do with >> different notations between them. But in any case, here is what I have: >> >> >>> type(Time) >> <class 'type'> >> >>> t1 = Time() >> >>> type(t1) >> <class '__main__.Time'> >> >> where: >> >> class Time: >> def __init__(self, hours = 0, minutes = 0, seconds = 0): >> self.hours = hours >> self.minutes = minutes >> self.seconds = seconds >> >> def print_time(t1): >> print(t.hours, ":", t.minutes, ":", t.seconds) >> >> Now the book I am working with has the following example: >> >> >>> type(Point) >> <type 'classobj'> >> >>> p = Point() >> >> >>> type(p) >> <type 'instance'> >> >> My questions are the following: >> 1) Why is the type for my class Time : >>> type(Time) >> <class >> 'type'> >> when the type for their class Point is: <type 'classobj'> >> Also, what is the difference between "class" and "classobj" in this case? >> 2) Why does my t1 object give the following as its type: <class >> '__main__.Time'> >> And in their p object example the type is: <type 'instance'>? >> 3) What is happening such that when I try to call my print_time(t1) >> function I get the following error: >> >>> t1 = Time() >> >>> t1.hours = 3 >> >>> t1.minutes = 30 >> >>> t1.seconds = 45 >> >>> print_time(t1) >> Traceback (most recent call last): >> File "<pyshell#77>", line 1, in <module> >> print_time(t1) >> NameError: name 'print_time' is not defined >> >> >> Thank you very much. >> >> Sincerely, >> >> Ben >> >> >
_______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor