On Wed, 17 Oct 2007 15:01:09 -0700, kiilerix wrote:
On Oct 17, 9:11 pm, Chris Mellon [EMAIL PROTECTED] wrote:
On 10/17/07, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote:
o = object()
o.foo = 7
What makes you think it can't be instantiated directly? You just did
it. It's not, however,
On Oct 7, 10:24 pm, [EMAIL PROTECTED] (Alex Martelli) wrote:
$ python -mtimeit -s'class A(object):pass' -s'a=A()' 'a.zop=23'
When I know that all instances of classes inheriting from object have
a namespace, then I would expect either that all objects have a
namespace or that it was inherited
On 10/17/07, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote:
On Oct 7, 10:24 pm, [EMAIL PROTECTED] (Alex Martelli) wrote:
$ python -mtimeit -s'class A(object):pass' -s'a=A()' 'a.zop=23'
When I know that all instances of classes inheriting from object have
a namespace, then I would expect either
On Oct 17, 9:11 pm, Chris Mellon [EMAIL PROTECTED] wrote:
On 10/17/07, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote:
o = object()
o.foo = 7
What makes you think it can't be instantiated directly? You just did
it. It's not, however, suitable for use as an arbitrary thing to stick
attributes
In article [EMAIL PROTECTED],
Steven Bethard [EMAIL PROTECTED] wrote:
Aahz wrote:
In article [EMAIL PROTECTED],
Steven Bethard [EMAIL PROTECTED] wrote:
You can use __slots__ [...]
Aaaugh! Don't use __slots__!
Seriously, __slots__ are for wizards writing applications with huuuge
Delaney, Timothy (Tim) wrote:
Licheng Fang wrote:
This is enlightening. Surely I shouldn't have worried too much about
performance before doing some measurement.
And with that statement you have truly achieved enlightenment.
Or to put it another way ... performance tuning without
Steven Bethard wrote:
Actually, your posting just used dicts normally.
Kevin is creating a prototype dict with a certain set of keys, and
then copying that dict and filling in the keys each time he
creates a new instance. It's basically a poor man's OOP.
And operatively, IMHO, there is no
On Oct 8, 4:24 am, [EMAIL PROTECTED] (Alex Martelli) wrote:
Licheng Fang [EMAIL PROTECTED] wrote:
...
Python Tutorial says an empty class can be used to do this. But if
namespaces are implemented as dicts, wouldn't it incur much overhead
if one defines empty classes as such for some
Am I missing something, or am I the only one who explicitly declares
structs in python?
For example:
FileObject = {
filename : None,
path : None,
}
fobj = FileObject.copy()
fobj[filename] = passwd
fobj[path] = /etc/
Kevin Kelley
On 10/7/07, Licheng Fang [EMAIL PROTECTED] wrote:
Kevin wrote:
Am I missing something, or am I the only one who explicitly declares
structs in python?
For example:
FileObject = {
filename : None,
path : None,
}
fobj = FileObject.copy()
fobj[filename] = passwd
fobj[path] = /etc/
Yes, I think this is the only time I've
On 10/10/07, Kevin [EMAIL PROTECTED] wrote:
Am I missing something, or am I the only one who explicitly declares
structs in python?
For example:
FileObject = {
filename : None,
path : None,
}
fobj = FileObject.copy()
fobj[filename] = passwd
fobj[path] = /etc/
I am pretty
Kevin wrote:
Am I missing something, or am I the only one who explicitly
declares structs in python?
Yes -- you missed my posting :)
Regards,
Björn
--
BOFH excuse #209:
Only people with names beginning with 'A' are getting mail this week
(a la Microsoft)
--
Bjoern Schliessmann wrote:
Kevin wrote:
Am I missing something, or am I the only one who explicitly
declares structs in python?
Yes -- you missed my posting :)
Actually, your posting just used dicts normally.
Kevin is creating a prototype dict with a certain set of keys, and then
copying
Licheng Fang wrote:
This is enlightening. Surely I shouldn't have worried too much about
performance before doing some measurement.
And with that statement you have truly achieved enlightenment.
Or to put it another way ... performance tuning without profiling is a
waste of time.
Tim Delaney
Brian Elmegaard a écrit :
Bruno Desthuilliers [EMAIL PROTECTED]
writes:
Use dicts, not lists or tuples:
a = dict(name='yadda', val=42)
print a['name']
print a['val']
I guess you will then need a list or tuple to store the dicts?
Should be a list then IMHO. But then it's the correct
On Sun, 07 Oct 2007 21:27:31 -0700, Aahz wrote:
In article [EMAIL PROTECTED], Steven
Bethard [EMAIL PROTECTED] wrote:
You can use __slots__ [...]
Aaaugh! Don't use __slots__!
Seriously, __slots__ are for wizards writing applications with huuuge
numbers of object instances (like,
Steven D'Aprano wrote:
On Sun, 07 Oct 2007 21:27:31 -0700, Aahz wrote:
In article [EMAIL PROTECTED], Steven
Bethard [EMAIL PROTECTED] wrote:
You can use __slots__ [...]
Aaaugh! Don't use __slots__!
Seriously, __slots__ are for wizards writing applications with huuuge
numbers of
On Mon, 08 Oct 2007 15:15:36 +0200, Diez B. Roggisch wrote:
Well, I've read the thread, and I've read the thread it links to, and
for the life of me I'm still no clearer as to why __slots__ shouldn't
be used except that:
1 Aahz and Guido say __slots__ are teh suxxor;
2 rumour (?) has it
Steven D'Aprano wrote:
On Mon, 08 Oct 2007 15:15:36 +0200, Diez B. Roggisch wrote:
Well, I've read the thread, and I've read the thread it links to, and
for the life of me I'm still no clearer as to why __slots__ shouldn't
be used except that:
1 Aahz and Guido say __slots__ are teh
Aahz wrote:
In article [EMAIL PROTECTED],
Steven Bethard [EMAIL PROTECTED] wrote:
You can use __slots__ [...]
Aaaugh! Don't use __slots__!
Seriously, __slots__ are for wizards writing applications with huuuge
numbers of object instances (like, millions of instances).
You clipped me
Licheng Fang wrote:
Python is supposed to be readable, but after programming in Python for
a while I find my Python programs can be more obfuscated than their C/C
++ counterparts sometimes. Part of the reason is that with
heterogeneous lists/tuples at hand, I tend to stuff many things into
Licheng Fang a écrit :
Python is supposed to be readable, but after programming in Python for
a while I find my Python programs can be more obfuscated than their C/C
++ counterparts sometimes. Part of the reason is that with
heterogeneous lists/tuples at hand, I tend to stuff many things into
Licheng Fang wrote:
struct nameval {
char * name;
int val;
} a;
a.name = ...
a.val = ...
becomes cryptic
a[0] = ...
a[1] = ...
?!
(1)
a = {}
a[name] = ...
a[val] = ...
(2)
NAME = 0
VAL = 1
a=[]
a[NAME] = ...
a[VAL] = ...
Python Tutorial says an empty class can be used
On Oct 7, 2:14 pm, Steven Bethard [EMAIL PROTECTED] wrote:
Licheng Fang wrote:
Python is supposed to be readable, but after programming in Python for
a while I find my Python programs can be more obfuscated than their C/C
++ counterparts sometimes. Part of the reason is that with
George Sakkis wrote:
On Oct 7, 2:14 pm, Steven Bethard [EMAIL PROTECTED] wrote:
Licheng Fang wrote:
Python is supposed to be readable, but after programming in Python for
a while I find my Python programs can be more obfuscated than their C/C
++ counterparts sometimes. Part of the reason is
Bruno Desthuilliers [EMAIL PROTECTED]
writes:
Use dicts, not lists or tuples:
a = dict(name='yadda', val=42)
print a['name']
print a['val']
I guess you will then need a list or tuple to store the dicts?
I might have made it with a list of class instances:
class a:
def
Licheng Fang [EMAIL PROTECTED] wrote:
...
Python Tutorial says an empty class can be used to do this. But if
namespaces are implemented as dicts, wouldn't it incur much overhead
if one defines empty classes as such for some very frequently used
data structures of the program?
Just measure:
On Oct 7, 1:07 pm, Licheng Fang [EMAIL PROTECTED] wrote:
Python is supposed to be readable, but after programming in Python for
a while I find my Python programs can be more obfuscated than their C/C
++ counterparts sometimes. Part of the reason is that with
heterogeneous lists/tuples at hand,
Licheng Fang wrote:
Python is supposed to be readable, but after programming in Python for
a while I find my Python programs can be more obfuscated than their C/C
++ counterparts sometimes. Part of the reason is that with
heterogeneous lists/tuples at hand, I tend to stuff many things into
On 8/10/2007 4:14 AM, Steven Bethard wrote:
Licheng Fang wrote:
Python is supposed to be readable, but after programming in Python for
a while I find my Python programs can be more obfuscated than their C/C
++ counterparts sometimes. Part of the reason is that with
heterogeneous lists/tuples
On Sun, 07 Oct 2007 13:24:14 -0700, Alex Martelli wrote:
And yes, you CAN save about 1/3 of those 85 nanoseconds by having
'__slots__=[zop]' in your class A(object)... but that's the kind of
thing one normally does only to tiny parts of one's program that have
been identified by profiling as
Steven D'Aprano [EMAIL PROTECTED] wrote:
On Sun, 07 Oct 2007 13:24:14 -0700, Alex Martelli wrote:
And yes, you CAN save about 1/3 of those 85 nanoseconds by having
'__slots__=[zop]' in your class A(object)... but that's the kind of
thing one normally does only to tiny parts of one's
Alex Martelli wrote:
Steven D'Aprano [EMAIL PROTECTED] wrote:
class Record(object):
__slots__ = [x, y, z]
has a couple of major advantages over:
class Record(object):
pass
aside from the micro-optimization that classes using __slots__ are faster
and smaller than classes with
In article [EMAIL PROTECTED],
Steven Bethard [EMAIL PROTECTED] wrote:
You can use __slots__ [...]
Aaaugh! Don't use __slots__!
Seriously, __slots__ are for wizards writing applications with huuuge
numbers of object instances (like, millions of instances). For an
extended thread about this,
On Oct 8, 12:27 am, [EMAIL PROTECTED] (Aahz) wrote:
Aaaugh! Don't use __slots__!
+1 QOTW ;)
Michele Simionato
--
http://mail.python.org/mailman/listinfo/python-list
On Oct 7, 7:58 pm, [EMAIL PROTECTED] (Alex Martelli) wrote:
If you REALLY pine for Pascal's records, you might choose to inherit
from ctypes.Structure, which has the additional advantages of
specifying a C type for each field and (a real advantage;-) creating an
appropriate __init__ method.
36 matches
Mail list logo