On Thu, Sep 29, 2011 at 7:53 AM, Tayfun Kayhan
<tayfun92_kay...@yahoo.com> wrote:
> def trial():
>    class Foo(object):
>       def __init__(self):
>          print("Hello, world!")
> trial() # not worked, as expected.

Python doesn't have "class declarations" in the way that some other
languages do. The 'class' statement is an executable statement - it
builds a class object and binds it to the name Foo, just like any
other assignment. The 'def' command builds a function object in a
similar fashion. So in your trial() function, you're defining a class
and binding it to the local name Foo; and then doing nothing with it.
It's perfectly legal, and as Chris Rebert suggests, you can make it
useful by instantiating Foo() objects inside trial().

ChrisA
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to