Duncan Booth <[EMAIL PROTECTED]> wrote in
news:[EMAIL PROTECTED]:
>> >>> def f():
>> class C(object):
>> def __init__(self):
>>self.a = 'a'
>> return C()
>>
>> >>> x = f()
>> >>> x.a
>> 'a'
>> >>> y=f.C()
>>
>
Of course there's this:
>>> def f():
... clas
Kay Schluehr wrote:
>
> Tomi Lindberg wrote:
>> Hi,
>>
>> With the following function definition, is it possible to
>> create an instance of class C outside the function f (and if
>> it is, how)?
>
> def f():
> class C(object):
> def __init__(self):
> self.a = 'a'
>
Peter Otten wrote:
> By the way you get an instance of a different class C every time you call f,
> so that
>
> isinstance(f(), type(f())
>
> is False.
That I didn't know. Well, that theory won't be seeing much
practice I guess.
--
Tomi Lindberg
--
http://mail.python.org/mailman/listinfo/pyt
Tomi Lindberg wrote:
> With the following function definition, is it possible to
> create an instance of class C outside the function f (and if
> it is, how)? And yes, I think this is one of those times
> when the real question is why :)
>
> >>> def f():
> class C(object):
> def
Tomi Lindberg wrote:
> With the following function definition, is it possible to
> create an instance of class C outside the function f (and if
> it is, how)? And yes, I think this is one of those times
> when the real question is why :)
>
> >>> def f():
> class C(object):
>
Diez B. Roggisch wrote:
> No, its not. Only inside of it. And the question really is: why?
Thanks. And no need to worry, the question was intended as
fully theoretical.
--
Tomi Lindberg
--
http://mail.python.org/mailman/listinfo/python-list
Tomi Lindberg wrote:
> Hi,
>
> With the following function definition, is it possible to
> create an instance of class C outside the function f (and if
> it is, how)?
def f():
class C(object):
def __init__(self):
self.a = 'a'
f.C = C
return C()
>>> f.C
>
Tomi Lindberg wrote:
> Hi,
>
> With the following function definition, is it possible to
> create an instance of class C outside the function f (and if
> it is, how)? And yes, I think this is one of those times
> when the real question is why :)
>
> >>> def f():
> class C(object):
> def __init_
Hi,
With the following function definition, is it possible to
create an instance of class C outside the function f (and if
it is, how)? And yes, I think this is one of those times
when the real question is why :)
>>> def f():
class C(object):
def __init__(self):