>> I don't think Steven cares much, he loves this type of nitpicking and
>> uber pedantic formulations, but only if he can apply it to other
>> people's post :)
>
> Heh heh :)
>
> I actually do care, because (not having a Java/C++ background) I actually
> do get a mental "double-take" every time I
On Mon, 21 Dec 2009 15:03:03 +0100, Daniel Fetchinson wrote:
> I don't think Steven cares much, he loves this type of nitpicking and
> uber pedantic formulations, but only if he can apply it to other
> people's post :)
Heh heh :)
I actually do care, because (not having a Java/C++ background) I a
>>> In python, 'class variable' is a variable that belongs to a class; not
>>> to the instance and is shared by all instance that belong to the class.
>>
>> Surely, since string variables are strings, and float variables are
>> floats, and bool variables are bools, and module variables are modules,
En Sun, 20 Dec 2009 01:16:16 -0300, Steven D'Aprano
escribió:
On Sun, 20 Dec 2009 11:44:11 +1100, Lie Ryan wrote:
In python, 'class variable' is a variable that belongs to a class; not
to the instance and is shared by all instance that belong to the class.
Surely, since string variables are
On Sat, 19 Dec 2009 20:28:07 -0800, Chris Rebert wrote:
>> Surely, since string variables are strings, and float variables are
>> floats, and bool variables are bools, and module variables are modules,
>> a class variable will be a class and an instance variable will be an
>> instance?
>
> As the
On Sat, Dec 19, 2009 at 8:16 PM, Steven D'Aprano
wrote:
> On Sun, 20 Dec 2009 11:44:11 +1100, Lie Ryan wrote:
>
>> In python, 'class variable' is a variable that belongs to a class; not
>> to the instance and is shared by all instance that belong to the class.
>
> Surely, since string variables ar
On Sun, 20 Dec 2009 11:44:11 +1100, Lie Ryan wrote:
> In python, 'class variable' is a variable that belongs to a class; not
> to the instance and is shared by all instance that belong to the class.
Surely, since string variables are strings, and float variables are
floats, and bool variables ar
On 12/20/2009 11:10 AM, KarlRixon wrote:
Given the following script, I'd expect p1.items to just contain
["foo"] and p2.items to contain ["bar"] but they both contain ["foo",
"bar"].
Why is this? Are object variables not specific to their instance?
First of all, dump all the preconception of w
On 19Dec2009 16:10, KarlRixon wrote:
| Given the following script, I'd expect p1.items to just contain
| ["foo"] and p2.items to contain ["bar"] but they both contain ["foo",
| "bar"].
|
| Why is this? Are object variables not specific to their instance?
You haven't instatiated "items" in the ob
Yes, if you want instance variables that are unique to each instance of a
class, do the following:
class Parser:
def __init__(self):
self.items = []
And that should work fine.
J:\_Programming Projects\Python>python test.py
<__main__.Parser object at 0x0240E7B0>
<__main__.Parser object
On Sat, 19 Dec 2009 19:10:13 -0500, KarlRixon wrote:
Given the following script, I'd expect p1.items to just contain
["foo"] and p2.items to contain ["bar"] but they both contain ["foo",
"bar"].
Why is this? Are object variables not specific to their instance?
---
#!/u
In article <9c848013-2245-455e-bb30-48e430d56...@j9g2000prh.googlegroups.com>,
wrote:
>
>I have a class whose job is to serve several other objects, [...]
Sorry, I'm finding it difficult to understand what you want. It looks
to me that you're confusing "object" and "instance", and I think you'
On 7/31/06, Bruno Desthuilliers <[EMAIL PROTECTED]> wrote:
> Colin J. Williams wrote:
> > Andre Meyer wrote:
> >> Hi all
> >>
> >> I am trying to understand the magic of Python's class variables and
> >> tried the following code (see below).
> >>
> >> Just out of curiosity, I tried to define a prop
Colin J. Williams wrote:
> Andre Meyer wrote:
>> Hi all
>>
>> I am trying to understand the magic of Python's class variables and
>> tried the following code (see below).
>>
>> Just out of curiosity, I tried to define a property that provides
>> access to a seemingly instancae variable which is in
python != java.
when you say "self.v = ...", you mask the class attribute with an
instance attribute.
say "C1.v = ...".
Colin J. Williams wrote:
> Andre Meyer wrote:
> > Hi all
> >
> > I am trying to understand the magic of Python's class variables and
> > tried the following code (see below).
> >
Andre Meyer wrote:
> Hi all
>
> I am trying to understand the magic of Python's class variables and
> tried the following code (see below).
>
> Just out of curiosity, I tried to define a property that provides access
> to a seemingly instancae variable which is in fact a class variable. All
>
[EMAIL PROTECTED] wrote:
> In passing, I have another question: where can I read up more on
> metaclasses?
Well, in "Python in a Nutshell" Alex Martelli manages to pack the practical
information that lets you work with metaclasses into just four pages,
including a two-page example. You may have s
Thank you Peter, this does the job.
In passing, I have another question: where can I read up more on
metaclasses?
Alain
--
http://mail.python.org/mailman/listinfo/python-list
[EMAIL PROTECTED] wrote:
>
> Peter Otten wrote:
>> [EMAIL PROTECTED] wrote:
>>
>> > Point.x=0 leads to having p.x==0
>> > It seems not possible to have class variables and instance variable
>> > having the same name and yet different values.
>>
>> A quick check:
>>
>> >>> class T(tuple):
>> ...
As an supplement to my previous post, please find hereunder a snippet
for my unsuccessful attempt (commented out snippet does not work):
def superTuple(*attribute_names):
nargs = len(attribute_names)
class T(tuple):
def __new__(cls, *args):
re
Peter Otten wrote:
> [EMAIL PROTECTED] wrote:
>
> > Point.x=0 leads to having p.x==0
> > It seems not possible to have class variables and instance variable
> > having the same name and yet different values.
>
> A quick check:
>
> >>> class T(tuple):
> ... class __metaclass__(type):
> ...
[EMAIL PROTECTED] wrote:
> Point.x=0 leads to having p.x==0
> It seems not possible to have class variables and instance variable
> having the same name and yet different values.
A quick check:
>>> class T(tuple):
... class __metaclass__(type):
... x = property(lambda cls: 0)
..
22 matches
Mail list logo