Ian Hobson於 2019年10月20日星期日 UTC+8下午6時05分11秒寫道:
> Hi Jach,
>
> On 20/10/2019 09:34, jf...@ms4.hinet.net wrote:
> > What puzzles me is how a parent's method foo() can find its child's method
> > goo(), no matter it was overwrote or not? MRO won't explain this and I
> > can't find document about it
On 10/20/19 4:34 AM, jf...@ms4.hinet.net wrote:
> Yes, there will be an attribute error if no goo() was defined.
>
> What puzzles me is how a parent's method foo() can find its child's method
> goo(), no matter it was overwrote or not? MRO won't explain this and I can't
> find document about it
On Sun, Oct 20, 2019 at 9:06 PM Ian Hobson wrote:
>
> Hi Jach,
>
> On 20/10/2019 09:34, jf...@ms4.hinet.net wrote:
> > What puzzles me is how a parent's method foo() can find its child's method
> > goo(), no matter it was overwrote or not? MRO won't explain this and I
> > can't find document abo
Hi Jach,
On 20/10/2019 09:34, jf...@ms4.hinet.net wrote:
What puzzles me is how a parent's method foo() can find its child's method
goo(), no matter it was overwrote or not? MRO won't explain this and I can't
find document about it also:-(
This is a generalised description - Python may be sl
Sibylle Koczian於 2019年10月20日星期日 UTC+8上午2時04分54秒寫道:
> Am 19.10.2019 um 13:11 schrieb jf...@ms4.hinet.net:
> > For the two examples below:
> > (1)
> class A:
> > ... def foo(self):
> > ... self.goo()
> > ...
> class B(A):
> > ... def goo(self):
> > ... print(1)
> > .
Am 19.10.2019 um 13:11 schrieb jf...@ms4.hinet.net:
For the two examples below:
(1)
class A:
... def foo(self):
... self.goo()
...
class B(A):
... def goo(self):
... print(1)
...
(2)
class A:
... def foo(self):
... self.goo()
... def goo(self): pass
For the two examples below:
(1)
>>> class A:
... def foo(self):
... self.goo()
...
>>> class B(A):
... def goo(self):
... print(1)
...
(2)
>>> class A:
... def foo(self):
... self.goo()
... def goo(self): pass
...
>>> class B(A):
... def goo(self):
...
ast wrote:
> Hello
>
> Following syntax doesn't generate any errors:
>
> >>> foo=0
> >>> Class Foo:
> foo
>
> But class Foo seems empty
>
> Is it equivalent to ?
>
> >>> class Foo:
> pass
The resulting class is equivalent, but the expression `foo` is actually
evaluated d
Hello
Following syntax doesn't generate any errors:
>>> foo=0
>>> Class Foo:
foo
But class Foo seems empty
Is it equivalent to ?
>>> class Foo:
pass
--
https://mail.python.org/mailman/listinfo/python-list
On 07Aug2019 16:36, Terry Reedy wrote:
On 8/7/2019 3:26 PM, Manfred Lotz wrote:
On Wed, 07 Aug 2019 14:39:00 -0400
Dennis Lee Bieber wrote:
On Wed, 7 Aug 2019 20:11:15 +0200, Manfred Lotz
declaimed the following:
More often I see something like this:
class Myclass:
...
but sometimes I see
On 8/7/2019 3:26 PM, Manfred Lotz wrote:
On Wed, 07 Aug 2019 14:39:00 -0400
Dennis Lee Bieber wrote:
On Wed, 7 Aug 2019 20:11:15 +0200, Manfred Lotz
declaimed the following:
Hi there,
More often I see something like this:
class Myclass:
...
but sometimes I see
class Myclass(object):
...
On Wed, 07 Aug 2019 14:39:00 -0400
Dennis Lee Bieber wrote:
> On Wed, 7 Aug 2019 20:11:15 +0200, Manfred Lotz
> declaimed the following:
>
> >Hi there,
> >More often I see something like this:
> >
> >class Myclass:
> >...
> >
> >
> >but sometimes I see
> >
> >class Myclass(object):
> >...
> >
>
Hi there,
More often I see something like this:
class Myclass:
...
but sometimes I see
class Myclass(object):
...
Question: which way is preferable?
--
Manfred
--
https://mail.python.org/mailman/listinfo/python-list
Alexey Muranov wrote:
x = 42
class C:
x = x # Works
I'd say it kind of works by accident, and is not really an
intended feature.
if Python does not allow to refer "simultaneously" to
variables from different scopes if they have the same name.
It seems perfectly reasonable to
On 5/8/18 3:55 AM, Alexey Muranov wrote:
Sorry, i was confused. I would say that this mostly works as
expected, though the difference between
x = 42
class C:
x = x # Works
and
def f2(a):
class D:
a = a # Does not work <
return D
is still surpr
Sorry, i was confused. I would say that this mostly works as expected,
though the difference between
x = 42
class C:
x = x # Works
and
def f2(a):
class D:
a = a # Does not work <
return D
is still surprising to me.
Otherwise, probably the solu
Python 3.5.1 (default, Jun 1 2016, 13:15:26)
[GCC 4.2.1 (Apple Inc. build 5664)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> def f(a):
... class D:
... pass
... D.a = a
... return D
...
>>> c = f(42)
>>> c
.D'>
>>> c.a
42
--
Greg
--
https://mail.pyth
To be more exact, i do see a few workarounds, for example:
def f4(a):
b = a
class D:
a = b # Works
return D
But this is not what i was hoping for.
Alexey.
On Tue, 8 May, 2018 at 12:02 AM, Alexey Muranov
wrote:
I have discovered the following bug or proble
I have discovered the following bug or problem: it looks like i am
forced to choose different names for class attributes and function
arguments, and i see no workaround. Am i missing some special syntax
feature ?
Alexey.
---
x = 42
class C1:
y = x # Works
class C2:
x = x # Works
#
Ben Finney wrote:
> Peter Otten <__pete...@web.de> writes:
>
>> Ben Finney wrote:
>>
>> > Peter Otten <__pete...@web.de> writes:
>> >
>> > That's an unexpected inconsistency between list comprehensions
>> > versus generator expressions, then. Is that documented explicitly in
>> > the Python 2 do
Peter Otten <__pete...@web.de> writes:
> Ben Finney wrote:
>
> > Peter Otten <__pete...@web.de> writes:
> >
> > That's an unexpected inconsistency between list comprehensions
> > versus generator expressions, then. Is that documented explicitly in
> > the Python 2 documentation?
>
> https://docs.
Ben Finney wrote:
> Peter Otten <__pete...@web.de> writes:
>
>> I would probably use a generator expression. These don't leak names:
>
> That's an unexpected inconsistency between list comprehensions versus
> generator expressions, then. Is that documented explicitly in the Python
> 2 documentat
MRAB writes:
> Have you thought about catching the NameError?
I had not, but that is obvious now you say it. Thanks.
Where there isn't a more elegant solution, I'll use that. It might not
be elegant, but it's at least clear and expressive of the intent.
Jussi Piitulainen writes:
> Make them
Peter Otten <__pete...@web.de> writes:
> I would probably use a generator expression. These don't leak names:
That's an unexpected inconsistency between list comprehensions versus
generator expressions, then. Is that documented explicitly in the Python
2 documentation?
> Python 2.7.6 (default, J
Ben Finney writes:
> How can I ensure incidental names don't end up in the class
> definition, with code that works on both Python 2 and Python 3?
>
> With the following class definition, the incidental names `foo` and
> `bar`, only needed for the list comprehension, r
On Thu, Aug 13, 2015 at 1:39 AM, Peter Otten <__pete...@web.de> wrote:
> But I would probably use a generator expression. These don't leak names:
>
> Python 2.7.6 (default, Jun 22 2015, 17:58:13)
> [GCC 4.8.2] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
c
Ben Finney wrote:
> How can I ensure incidental names don't end up in the class definition,
> with code that works on both Python 2 and Python 3?
>
> With the following class definition, the incidental names `foo` and
> `bar`, only needed for the list comprehension, r
On 2015-08-12 10:01, Ben Finney wrote:
How can I ensure incidental names don't end up in the class definition,
with code that works on both Python 2 and Python 3?
With the following class definition, the incidental names `foo` and
`bar`, only needed for the list comprehension, remain i
tiful"]
> del foo, bar # ← FAILS, “NameError: name 'foo' is not defined”
>
> How can I write the class definition with the list comprehension and
> *not* keep the incidental names — in code that will run correctly on
> both Python 2 and Python 3?
You could alwa
How can I ensure incidental names don't end up in the class definition,
with code that works on both Python 2 and Python 3?
With the following class definition, the incidental names `foo` and
`bar`, only needed for the list comprehension, remain in the `Parrot`
namespace::
__metacl
> from kivy.app import App
> from kivy.uix.label import Label
>
> class MyApp(App):
> def build(self):
> return Label(text='Hello World')
>
> if __name__ == '__main__':
> MyApp().run()
>
>
>
> I get this error when I run it:
>
>
> Traceback (most recent call last):
> File
> Unindent the 'if' statement. Currently, it's indented inside the class
> definition, so MyApp isn't defined yet.
Thanks very much. That fixed it.
Best regards
David
--
https://mail.python.org/mailman/listinfo/python-list
Unindent the 'if' statement. Currently, it's indented inside the class
definition, so MyApp isn't defined yet.
--
https://mail.python.org/mailman/listinfo/python-list
Hi
I am just getting started with Python 3.3.3 and Kivy 1.8.
I am using the Kivy development environment on Windows (open a command prompt
and call kivy.bat).
With this minimal code:
import kivy
kivy.require('1.8.0')
from kivy.app import App
from kivy.uix.label import Label
class MyApp(App)
On 01/12/2015 08:49 PM, Steven D'Aprano wrote:
> On Mon, 12 Jan 2015 12:40:13 -0800, Ethan Furman wrote:
>>
>> [...] class name lookup skips nonlocal namespaces.
>
> Actually, no it doesn't.
> [...]
> The "problem" is that *functions* lookup don't include the class body in
> their scope.
Ah, t
On Mon, 12 Jan 2015 12:40:13 -0800, Ethan Furman wrote:
> On 01/12/2015 12:25 PM, John Ladasky wrote:
>> d = {0:"a", 1:"b", 2:"c", 3:"d"}
>> e = [d[x] for x in (0,2)]
>>
>> class Foo:
>> f = {0:"a", 1:"b", 2:"c", 3:"d"}
>> print(f)
>> g = [f[x] for x in (0,2)]
>
> In Foo 'f' is part
On Tue, Jan 13, 2015 at 7:25 AM, John Ladasky
wrote:
> When I am working inside the class namespace, the print function call on line
> 8 recognizes the name f and prints the dictionary bound to that name.
>
> However, the LIST COMPREHENSION defined inside the class namespace generates
> a NameEr
On Monday, January 12, 2015 at 12:41:30 PM UTC-8, Ethan Furman wrote:
> In Foo 'f' is part of an unnamed namespace; the list comp 'g' has its own
> namespace, effectively making be a nonlocal;
> class name lookup skips nonlocal namespaces.
>
> Workaround: use an actual for loop.
Thanks, Ethan.
Following up to myself: I finally did the right keyword search, and found a
relevant article:
http://stackoverflow.com/questions/13905741/accessing-class-variables-from-a-list-comprehension-in-the-class-definition
Maybe I HAVE tried to define a list comprehension inside a class definition
On 01/12/2015 12:25 PM, John Ladasky wrote:
> d = {0:"a", 1:"b", 2:"c", 3:"d"}
> e = [d[x] for x in (0,2)]
>
> class Foo:
> f = {0:"a", 1:"b", 2:"c", 3:"d"}
> print(f)
> g = [f[x] for x in (0,2)]
In Foo 'f' is part of an unnamed namespace; the list comp 'g' has its own
namespace, eff
I've never come across this before. Here's a minimal example (in Python 3.4):
Code:
-
d = {0:"a", 1:"b", 2:"c", 3:"d"}
e = [d[x] for x in (0,2)]
class Foo:
f = {0:"a", 1:"b", 2:"c", 3:"d"}
print(f)
g = [f[x] for x
On Jan 4, 11:46 pm, Inyeol wrote:
> Which coding style do you prefer? I'm more toward public API way,
> since it requires less code change if I refactor private data
> structure later.
> Plz give pros and cons of these.
Great question. It gets at the heart of Python style.
It's a tricky question
On Wed, Jan 5, 2011 at 9:15 AM, Peter Otten <__pete...@web.de> wrote:
> Jacek Krysztofik wrote:
>
> > Sorry for OT, but this is actually a question of mine
> >> if numbers % 2 == 0:
> > wouldn't the following be faster?
> >> if numbers & 1 == 0:
>
> You can answer t
Inyeol writes:
> def get_all(self):
> for number in self._numbers:
> yield number
I think
def get_all(self):
return iter(self._numbers)
is more direct.
--
http://mail.python.org/mailman/listinfo/python-list
Jacek Krysztofik wrote:
> Sorry for OT, but this is actually a question of mine
>> if numbers % 2 == 0:
> wouldn't the following be faster?
>> if numbers & 1 == 0:
You can answer that and similar questions yourself with the timeit module:
$ python -m timeit -s'm,
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA256
Sorry for OT, but this is actually a question of mine
> if numbers % 2 == 0:
wouldn't the following be faster?
> if numbers & 1 == 0:
JK
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.10 (GNU/Linux)
Comment: Using G
On 2011-01-05, Inyeol wrote:
> For example: I'm writing simple class:
>
> class Numbers:
> def __init__(self, numbers):
> self._numbers = numbers
> def get_all(self):
> for number in self._numbers:
> yield number
>
> If I want to add anot
Inyeol wrote:
For example: I'm writing simple class:
class Numbers:
def __init__(self, numbers):
self._numbers = numbers
def get_all(self):
for number in self._numbers:
yield number
If I want to add another method for yielding even num
On Jan 4, 8:46 pm, Inyeol wrote:
> For example: I'm writing simple class:
>
> class Numbers:
> def __init__(self, numbers):
> self._numbers = numbers
> def get_all(self):
> for number in self._numbers:
> yield number
>
> If I want to add
I think it depends on where you're willing to deal with changes. As it stands,
if you make changes to get_all that will effect the way get_even works. If
there's a logical chain that your code needs to follow and such changes would
be acceptable, use them, because it's easier to change one thing
I found typo after posting: local name 'numbers' and 'number' are
mixed.
Plz don't report bug but focus on coding style only :-)
--
http://mail.python.org/mailman/listinfo/python-list
For example: I'm writing simple class:
class Numbers:
def __init__(self, numbers):
self._numbers = numbers
def get_all(self):
for number in self._numbers:
yield number
If I want to add another method for yielding even numbers only, I may
harryos a écrit :
hi
i have seen some class definitions like
class MyClass(object):
def __init__(self):
what does the object keyword
It's not a keyword.
inside the braces in MyClass() mean?
Answer is here:
http://docs.python.org/tut/node11.html#SECTION00115000
harryos wrote:
hi
i have seen some class definitions like
class MyClass(object):
def __init__(self):
what does the object keyword inside the braces in MyClass() mean?
Has it got any significance?
thanks in advance
harry
It is a syntax used for 'new type' classes, not so new a
On Fri, 29 Aug 2008 02:50:57 -0700 (PDT), harryos wrote:
> class MyClass(object):
> def __init__(self):
>
>
> what does the object keyword inside the braces in MyClass() mean?
> Has it got any significance?
It's inheritance. MyClass class inherits from object class.
Check out poin
harryos wrote:
> hi
> i have seen some class definitions like
>
> class MyClass(object):
> def __init__(self):
>
>
> what does the object keyword inside the braces in MyClass() mean?
> Has it got any significance?
It indicates a so-called new-style-class. The new style classes h
hi
i have seen some class definitions like
class MyClass(object):
def __init__(self):
what does the object keyword inside the braces in MyClass() mean?
Has it got any significance?
thanks in advance
harry
--
http://mail.python.org/mailman/listinfo/python-list
On Aug 5, 12:53 am, Michele Simionato <[EMAIL PROTECTED]>
wrote:
> BTW, since I do not really follow python-dev, do you know
> if some consensus was reached on the issue of adding an ordered dict
> implementation to the standard library?
I believe it has been deferred to 2.7/3.1.
--
http://mail.p
On Aug 10, 12:14 am, thebjorn
> > FWIW, I have just finished translating the first
> > part of the article and I have posted it on my
> > blog on Artima:
>
> >http://www.artima.com/weblogs/viewpost.jsp?thread=236234
>
> Great feature and great article! I haven't used ABCs yet, so my
> initial inst
On Aug 9, 7:55 am, Michele Simionato <[EMAIL PROTECTED]>
wrote:
> On Aug 5, 5:05 am, Michele Simionato
>
> > Yep. Seehttp://stacktrace.it/articoli/2008/01/metaclassi-python-3000
> > (I am working on an English translation these days,
> > but for the moment you can use Google Translator).
>
> > M.
On Aug 5, 5:05 am, Michele Simionato
> Yep. Seehttp://stacktrace.it/articoli/2008/01/metaclassi-python-3000
> (I am working on an English translation these days,
> but for the moment you can use Google Translator).
>
> M. Simionato
FWIW, I have just finished translating the first
part of the arti
Michele Simionato wrote:
BTW, since I do not really follow python-dev, do you know
if some consensus was reached on the issue of adding an ordered dict
implementation to the standard library?
I thought there was to be one added to collections, where default_dict
lives, but I do not remember
En Tue, 05 Aug 2008 00:05:58 -0300, Michele Simionato
<[EMAIL PROTECTED]> escribió:
On Aug 5, 4:38 am, "Gabriel Genellina":
So the namespace that the metaclass receives when the class is created,
will be some kind of ordered dictionary?
Metaclasses are available for a long time ago, but th
On Aug 5, 7:47 am, Terry Reedy <[EMAIL PROTECTED]> wrote:
>
> Bfiefly, as I understood the discussion some months ago: In 2.x, the
> class body is executed in a local namespace implemented as a normal dict
> and *then* passed to the metaclass. In 3.0, the metaclass gets brief
> control *before* ex
Michele Simionato wrote:
On Aug 5, 4:38 am, "Gabriel Genellina":
So the namespace that the metaclass receives when the class is created,
will be some kind of ordered dictionary?
Metaclasses are available for a long time ago, but the definition order is
lost right at the start, when the clas
On Aug 5, 4:38 am, "Gabriel Genellina":
>
> So the namespace that the metaclass receives when the class is created,
> will be some kind of ordered dictionary?
> Metaclasses are available for a long time ago, but the definition order is
> lost right at the start, when the class body is executed.
En Fri, 01 Aug 2008 23:47:42 -0300, Benjamin <[EMAIL PROTECTED]>
escribió:
On Aug 1, 6:23 pm, Andrew Lentvorski <[EMAIL PROTECTED]> wrote:
How do I determine the order of definition of class attributes?
For example, if I have a class
class Test(object):
y = 11
x = 22
How do I tell
On Aug 1, 6:23 pm, Andrew Lentvorski <[EMAIL PROTECTED]> wrote:
> How do I determine the order of definition of class attributes?
>
> For example, if I have a class
>
> class Test(object):
> y = 11
> x = 22
>
> How do I tell that y was defined before x?
You wait until Python 3.0 where yo
Andrew Lentvorski <[EMAIL PROTECTED]> writes:
> How do I determine the order of definition of class attributes?
>
> For example, if I have a class
>
> class Test(object):
> y = 11
> x = 22
>
> How do I tell that y was defined before x?
Like any namespace, attributes of an object are im
On Fri, Aug 1, 2008 at 7:23 PM, Andrew Lentvorski <[EMAIL PROTECTED]> wrote:
> How do I determine the order of definition of class attributes?
>
> For example, if I have a class
>
> class Test(object):
>y = 11
>x = 22
>
> How do I tell that y was defined before x?
You can't. The order tha
How do I determine the order of definition of class attributes?
For example, if I have a class
class Test(object):
y = 11
x = 22
How do I tell that y was defined before x?
Thanks,
-a
--
http://mail.python.org/mailman/listinfo/python-list
Ah, I see. Thank you all.
--
http://mail.python.org/mailman/listinfo/python-list
WaterWalk a écrit :
Hello. Consider the following two examples:
class Test1(object):
att1 = 1
def func(self):
print Test1.att1// ok
or
print type(self).att1
class Test2(object):
att1 = 1
att2 = Test2.att1 // NameError: Name Test2 is not defined
It seem
On Tue, 17 Jun 2008 23:05:56 -0700, WaterWalk wrote:
> Hello. Consider the following two examples: class Test1(object):
> att1 = 1
> def func(self):
> print Test1.att1// ok
>
> class Test2(object):
> att1 = 1
> att2 = Test2.att1 // NameError: Name Test2 is not defined
Hello. Consider the following two examples:
class Test1(object):
att1 = 1
def func(self):
print Test1.att1// ok
class Test2(object):
att1 = 1
att2 = Test2.att1 // NameError: Name Test2 is not defined
It seems a little strange. Why a class name can be used in a method
"Miles" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
| On Wed, May 7, 2008 at 7:40 PM, Yves Dorfsman <[EMAIL PROTECTED]> wrote:
| > Does it make a difference if you put subclass object or not ?
| Old-style | classes will go away in Python 3 (I think),
Have gone ;-)
| and all cla
Miles wrote:
In Python 2.2, classes and types were unified. If a class inherits
from object (or any other built-in), it is considered a "new-style"
class; otherwise, it is an old-style (or classic) class. There are
some differences in their behavior; most notably, descriptors
(computer propert
On Wed, May 7, 2008 at 7:40 PM, Yves Dorfsman <[EMAIL PROTECTED]> wrote:
> Does it make a difference if you put subclass object or not ?
>
> What is the difference between c1 and c2 here:
>
> class c1:
> pass
>
> class c2(object):
> pass
>>> type(c1)
>>> type(c1())
>>> type(c2)
>>> type(
Does it make a difference if you put subclass object or not ?
What is the difference between c1 and c2 here:
class c1:
pass
class c2(object):
pass
Thanks,
Yves.
http://www.SollerS.ca
--
http://mail.python.org/mailman/listinfo/python-list
On Fri, 07 Mar 2008 09:49:58 -0800, Krishna wrote:
> I am more interested in knowing about the first argument ('self'), what
> does it hold to allow the evaluation of the method, take the example you
> gave, 'self.a' as Rvalue inside the method, how and why is this allowed,
"self" is treated as a
uot;, line 1, in ?
> > > File "", line 4, in Test
> > > NameError: name 'self' is not defined
>
> > > In the 'definition of the class', what would the first argument 'self'
> > > in the methods evaluate to; when we hav
t; > In the 'definition of the class', what would the first argument 'self'
> > in the methods evaluate to; when we have an object defined, it is
> > bound to the object reference, but what happens while the class
> > definition is executed, which I believe
call last):
> File "", line 1, in ?
> File "", line 4, in Test
> NameError: name 'self' is not defined
>>>>
>
> In the 'definition of the class', what would the first argument 'self'
> in the methods evaluate to; whe
defined
>>>
In the 'definition of the class', what would the first argument 'self'
in the methods evaluate to; when we have an object defined, it is
bound to the object reference, but what happens while the class
definition is executed, which I believe happens whe
Terry Reedy wrote:
> "Maric Michaud" <[EMAIL PROTECTED]> wrote in message
> news:[EMAIL PROTECTED]
> |I faced a strange behavior with generator expression, which seems like a
> bug, for both
> | python 2.4 and 2.5 :
>
> Including the latest release (2.5.2)?
>
> | >>> class A :
> | ... a = 1
"Maric Michaud" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
|I faced a strange behavior with generator expression, which seems like a
bug, for both
| python 2.4 and 2.5 :
Including the latest release (2.5.2)?
| >>> class A :
| ... a = 1, 2, 3
| ... b = 1, 2, 3
| ...
I faced a strange behavior with generator expression, which seems like a bug,
for both
python 2.4 and 2.5 :
>>> class A :
... a = 1, 2, 3
... b = 1, 2, 3
... C = list((e,f) for e in a for f in b)
...
Traceback (most recent call last):
File "", line 1, in
File "", line 4, in A
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):
[EMAIL PROTECTED] wrote:
> Hi,
>
> Is it possible to split a Class definition over two or more text files?
Yes, but not directly. Could you tell us why you think you have such a
need ?
> (if so, how:)
Please answer my previous question first !-)
--
bruno desthuilliers
pyth
[EMAIL PROTECTED] schrieb:
> Hi,
>
> Is it possible to split a Class definition over two or more text files?
> (if so, how:)
Not in that sense. But if you must, you can use several classes and then
a resulting class that inherits from all of these.
Diez
--
http://mail.python
<[EMAIL PROTECTED]> wrote:
> Is it possible to split a Class definition over two or more text files?
> (if so, how:)
There's no partial types like in .NET 2.0 but since Python is dynamic
you can add members at runtime :-)
--
Lawrence - http://www.oluyede.org/blog
"Not
Hi,
Is it possible to split a Class definition over two or more text files?
(if so, how:)
Jerry
--
http://mail.python.org/mailman/listinfo/python-list
1 - 100 of 110 matches
Mail list logo