Re: Structures

2008-11-04 Thread George Sakkis
On Nov 3, 10:26 pm, Steven D'Aprano <[EMAIL PROTECTED] cybersource.com.au> wrote: > On Tue, 04 Nov 2008 00:19:16 +, Marc 'BlackJack' Rintsch wrote: > > On Mon, 03 Nov 2008 23:32:25 +, Paulo J. Matos wrote: > > >> What's then the reason for adding named tuples if they are not > >> mutable...

Re: Structures

2008-11-04 Thread Duncan Booth
Michele Simionato <[EMAIL PROTECTED]> wrote: > I did not expect such a large difference in instantiation time. > However I was thinking about > access time, and then the difference is not impressive (~20-25%): > The difference in time is because when you create a normal instance Python has to c

Re: Structures

2008-11-04 Thread Arnaud Delobelle
Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> writes: > On Mon, 03 Nov 2008 23:32:25 +, Paulo J. Matos wrote: > >> What's then the reason for adding named tuples if they are not >> mutable...??? > > Names are more descriptive than "magic numbers" as indices. See for > example the "named tuple

Re: Structures

2008-11-04 Thread Michele Simionato
On Nov 4, 11:20 am, [EMAIL PROTECTED] wrote: > Michele Simionato: > > > No, slots have nothing to do with speed, they are a memory optimization. > > In many languages, often in Python too, the less memory you use/ > allocate the faster you go. > > In fact slots allow a speed increase too (in new st

Re: Structures

2008-11-04 Thread bearophileHUGS
Michele Simionato: > No, slots have nothing to do with speed, they are a memory optimization. In many languages, often in Python too, the less memory you use/ allocate the faster you go. In fact slots allow a speed increase too (in new style classes): from timeit import default_timer as clock c

Re: Structures

2008-11-04 Thread Bruno Desthuilliers
Paulo J. Matos a écrit : (snip) However, I wouldn't dare to say Python needs structures to be a good language, or anything similar. My question was more directed to : if there aren't structures in Python, what do Pythonists use instead? (I have seen dicts might be an alternative, Yes, and the

Re: Structures

2008-11-04 Thread Bruno Desthuilliers
Joe Strout a écrit : On Nov 3, 2008, at 4:38 PM, Paulo J. Matos wrote: However, I wouldn't dare to say Python needs structures to be a good language, or anything similar. My question was more directed to : if there aren't structures in Python, what do Pythonists use instead? Classes. or obj

Re: Structures

2008-11-03 Thread Michele Simionato
On Nov 4, 2:57 am, Glenn Linderman <[EMAIL PROTECTED]> wrote: > Note that classes, by default, are based on a contained dict!  There are > games to be played with slots that can apparently improve that.  I am > not yet experienced enough with Python to know if a slot is as fast as a > C struct, but

Re: Structures

2008-11-03 Thread Glenn Linderman
On approximately 11/3/2008 5:28 PM, came the following characters from the keyboard of Aaron Brady: On Nov 3, 5:38 pm, "Paulo J. Matos" <[EMAIL PROTECTED]> wrote: On Mon, Nov 3, 2008 at 10:19 PM, Aaron Brady <[EMAIL PROTECTED]> wrote: On Nov 3, 3:45 pm, Ben Finney <[EMAIL PROTECTED]> wr

Re: Structures

2008-11-03 Thread Steven D'Aprano
On Tue, 04 Nov 2008 00:19:16 +, Marc 'BlackJack' Rintsch wrote: > On Mon, 03 Nov 2008 23:32:25 +, Paulo J. Matos wrote: > >> What's then the reason for adding named tuples if they are not >> mutable...??? > > Names are more descriptive than "magic numbers" as indices. See for > example

Re: Structures

2008-11-03 Thread Steven D'Aprano
On Mon, 03 Nov 2008 17:06:07 -0800, Aaron Brady wrote: >> For all practical purposes, dicts have almost constant access time (at >> least with any half-decent __hash__  method). > > Hash tables are slick, but their hash function is their weakest link. > [ hash( 2**x ) for x in range( 0, 256

Re: Structures

2008-11-03 Thread Glenn Linderman
On approximately 11/3/2008 3:38 PM, came the following characters from the keyboard of Paulo J. Matos: On Mon, Nov 3, 2008 at 10:19 PM, Aaron Brady <[EMAIL PROTECTED]> wrote: On Nov 3, 3:45 pm, Ben Finney <[EMAIL PROTECTED]> wrote: "Paulo J. Matos" <[EMAIL PROTECTED]> writes: O

Re: Structures

2008-11-03 Thread Aaron Brady
On Nov 3, 5:38 pm, "Paulo J. Matos" <[EMAIL PROTECTED]> wrote: > On Mon, Nov 3, 2008 at 10:19 PM, Aaron Brady <[EMAIL PROTECTED]> wrote: > > On Nov 3, 3:45 pm, Ben Finney <[EMAIL PROTECTED]> > > wrote: > >> "Paulo J. Matos" <[EMAIL PROTECTED]> writes: > >> Take care with broad sweeping statements a

Re: Structures

2008-11-03 Thread Aaron Brady
On Nov 3, 6:33 pm, George Sakkis <[EMAIL PROTECTED]> wrote: > On Nov 3, 6:32 pm, "Paulo J. Matos" <[EMAIL PROTECTED]> wrote: > > > Even though I can use dicts where the keys are strings (as if it were > > the name of the field), it seems to heavy, since a structure doesn't > > need to be resizable

Re: Structures

2008-11-03 Thread George Sakkis
On Nov 3, 6:32 pm, "Paulo J. Matos" <[EMAIL PROTECTED]> wrote: > Even though I can use dicts where the keys are strings (as if it were > the name of the field), it seems to heavy, since a structure doesn't > need to be resizable (and dicts are) and it has constant time access > (which depending on

Re: Structures

2008-11-03 Thread Paul Rubin
"Paulo J. Matos" <[EMAIL PROTECTED]> writes: > OK, so this is now messing with my lack of knowledge regarding Python. > What's (pure) Python? Is there any impure Python? impure Python = Python with extensions written in C. -- http://mail.python.org/mailman/listinfo/python-list

Re: Structures

2008-11-03 Thread Paulo J. Matos
On Tue, Nov 4, 2008 at 12:17 AM, George Sakkis <[EMAIL PROTECTED]> wrote: > > Technically there are no private attributes in (pure) Python so the > answer is still classes. > OK, so this is now messing with my lack of knowledge regarding Python. What's (pure) Python? Is there any impure Python? >

Re: Structures

2008-11-03 Thread Marc 'BlackJack' Rintsch
On Mon, 03 Nov 2008 23:32:25 +, Paulo J. Matos wrote: > What's then the reason for adding named tuples if they are not > mutable...??? Names are more descriptive than "magic numbers" as indices. See for example the "named tuple" returned by `os.stat()`. Ciao, Marc 'BlackJack' Rints

Re: Structures

2008-11-03 Thread George Sakkis
On Nov 3, 6:51 pm, "Paulo J. Matos" <[EMAIL PROTECTED]> wrote: > On Mon, Nov 3, 2008 at 11:47 PM, Joe Strout <[EMAIL PROTECTED]> wrote: > > On Nov 3, 2008, at 4:38 PM, Paulo J. Matos wrote: > > >> However, I wouldn't dare to say Python needs structures to be a good > >> language, or anything simila

Re: Structures

2008-11-03 Thread Paulo J. Matos
On Mon, Nov 3, 2008 at 11:47 PM, Joe Strout <[EMAIL PROTECTED]> wrote: > On Nov 3, 2008, at 4:38 PM, Paulo J. Matos wrote: > >> However, I wouldn't dare to say Python needs structures to be a good >> language, or anything similar. My question was more directed to : if >> there aren't structures in

Re: Structures

2008-11-03 Thread Joe Strout
On Nov 3, 2008, at 4:38 PM, Paulo J. Matos wrote: However, I wouldn't dare to say Python needs structures to be a good language, or anything similar. My question was more directed to : if there aren't structures in Python, what do Pythonists use instead? Classes. Best, - Joe -- http://mail.

Re: Structures

2008-11-03 Thread Paulo J. Matos
On Mon, Nov 3, 2008 at 10:19 PM, Aaron Brady <[EMAIL PROTECTED]> wrote: > On Nov 3, 3:45 pm, Ben Finney <[EMAIL PROTECTED]> > wrote: >> "Paulo J. Matos" <[EMAIL PROTECTED]> writes: >> >> > On Mon, Nov 3, 2008 at 12:32 PM, Ben Finney >> > <[EMAIL PROTECTED]> wrote: >> > > I'm wondering a more fundam

Re: Structures

2008-11-03 Thread Paulo J. Matos
On Mon, Nov 3, 2008 at 10:10 PM, Arnaud Delobelle <[EMAIL PROTECTED]> wrote: > Ben Finney <[EMAIL PROTECTED]> writes: > >> "Paulo J. Matos" <[EMAIL PROTECTED]> writes: > [...] >> Okay, you're talking about 'struct' from the C language. That helps >> answer the question. > > Note that structs are mu

Re: Structures

2008-11-03 Thread Arnaud Delobelle
Craig Allen <[EMAIL PROTECTED]> writes: >> >> Care to say more about what they are, not what they're like? >> > > I'm not the OP and I may be biased by C++, I can imagine the > complaints when I say, classes are just structures with function > members for working on the structure. In C++ classes

Re: Structures

2008-11-03 Thread Craig Allen
> > Care to say more about what they are, not what they're like? > I'm not the OP and I may be biased by C++, I can imagine the complaints when I say, classes are just structures with function members for working on the structure. -- http://mail.python.org/mailman/listinfo/python-list

Re: Structures

2008-11-03 Thread Aaron Brady
On Nov 3, 3:45 pm, Ben Finney <[EMAIL PROTECTED]> wrote: > "Paulo J. Matos" <[EMAIL PROTECTED]> writes: > > > On Mon, Nov 3, 2008 at 12:32 PM, Ben Finney > > <[EMAIL PROTECTED]> wrote: > > > I'm wondering a more fundamental question: What are structures? > > > That is, what do *you* mean by that te

Re: Structures

2008-11-03 Thread Arnaud Delobelle
Ben Finney <[EMAIL PROTECTED]> writes: > "Paulo J. Matos" <[EMAIL PROTECTED]> writes: [...] > Okay, you're talking about ‘struct’ from the C language. That helps > answer the question. Note that structs are mutable. > In Python, the way to do that is with a dict. A class can be used, but > is of

Re: Structures

2008-11-03 Thread Jorgen Grahn
On Mon, 3 Nov 2008 20:33:45 +, Paulo J. Matos <[EMAIL PROTECTED]> wrote: > On Mon, Nov 3, 2008 at 12:32 PM, Ben Finney > <[EMAIL PROTECTED]> wrote: >> "Paulo J. Matos" <[EMAIL PROTECTED]> writes: ... >> I'm wondering a more fundamental question: What are structures? That >> is, what do *you* me

Re: Structures

2008-11-03 Thread Ben Finney
"Paulo J. Matos" <[EMAIL PROTECTED]> writes: > On Mon, Nov 3, 2008 at 12:32 PM, Ben Finney > <[EMAIL PROTECTED]> wrote: > > I'm wondering a more fundamental question: What are structures? > > That is, what do *you* mean by that term; without knowing that, an > > answer isn't likely to be meaningfu

Re: Structures

2008-11-03 Thread Paulo J. Matos
On Mon, Nov 3, 2008 at 12:32 PM, Ben Finney <[EMAIL PROTECTED]> wrote: > "Paulo J. Matos" <[EMAIL PROTECTED]> writes: > >> I am a Python beginner, reading through 2.6 tutorial. I am wondering >> where are structures? > > I'm wondering a more fundamental question: What are structures? That > is, wha

Re: Structures

2008-11-03 Thread Ben Finney
"Paulo J. Matos" <[EMAIL PROTECTED]> writes: > I am a Python beginner, reading through 2.6 tutorial. I am wondering > where are structures? I'm wondering a more fundamental question: What are structures? That is, what do *you* mean by that term; without knowing that, an answer isn't likely to be

Re: Structures

2008-11-03 Thread Steve Holden
Paulo J. Matos wrote: > Hi all, > > I am a Python beginner, reading through 2.6 tutorial. I am wondering > where are structures? > > On the other hand, I think I might have the answer. Since Python focus > on having one way to do it and structures are something like classes > with only public met

Re: Structures

2008-11-03 Thread bearophileHUGS
Paulo J. Matos: > Since Python focus > on having one way to do it and structures are something like classes > with only public methods, if I want structures that's what I should use. > Is that right? Yes, it is. On the other hand in Python 2.6 there's something that helps you build one of such cla