Ilan | 1 Jun 01:49 2008
Picon

Re: a python meeting in TLV

Peace, Pythonists,

Nu, when and where do we meet?

I'd like to present and discuss Web development with Python. 
Specifically:
* Persistence
* Testing
* Alternative approaches to CMS implementation

Am preparing these topics now. Write if you want to "signal" 
anything.

Please make it happen before the 18th. I don't want to miss this 
meeting.

Thanks!
;o)

--

-- 
Ilan

Any technology distinguishable from magic is insufficiently 
advanced.
_______________________________________________
Python-il mailing list
Python-il <at> hamakor.org.il
http://hamakor.org.il/cgi-bin/mailman/listinfo/python-il
Omer Zak | 11 Jun 14:28 2008
Picon

The Tuples and Lists question

I have a silly question:
Why does Python have both Tuples and Lists?

The only programmer-visible difference, of which I am aware, between
them is that Tuples are immutable and Lists are mutable, with the
following implications:
1. Tuples can be used as hash (Dict) keys, and Lists cannot.
2. When you modify a Tuple, a new Tuple is created.  On the other hand,
List modification happens in place.

I don't see why is the above difference good enough reason to have
different notations for Tuples and Lists.
                                           --- Omer
--

-- 
Every good master plan involves building a time machine.  Moshe Zadka
My own blog is at http://www.zak.co.il/tddpirate/

My opinions, as expressed in this E-mail message, are mine alone.
They do not represent the official policy of any organization with which
I may be affiliated in any way.
WARNING TO SPAMMERS:  at http://www.zak.co.il/spamwarning.html

_______________________________________________
Python-il mailing list
Python-il <at> hamakor.org.il
http://hamakor.org.il/cgi-bin/mailman/listinfo/python-il
Omer Zak | 11 Jun 14:33 2008
Picon

A blast from the past - an interview with Guido van Rossum about the CP4E project

http://www.linuxjournal.com/article/5028
This interview is dated from Sept. 28, 1999, and the CP4E project was to
be about teaching Python to people, who are not going to be professional
software developers.
I wonder whether there are any materials from the attempt, which can be
ressurected and adapted for teaching Python 2.5 to non-software people.

                                               --- Omer
--

-- 
My Commodore 64 is suffering from slowness and insufficiency of memory;
and its display device is grievously short of pixels.  Can anyone help?
My own blog is at http://www.zak.co.il/tddpirate/

My opinions, as expressed in this E-mail message, are mine alone.
They do not represent the official policy of any organization with which
I may be affiliated in any way.
WARNING TO SPAMMERS:  at http://www.zak.co.il/spamwarning.html

_______________________________________________
Python-il mailing list
Python-il <at> hamakor.org.il
http://hamakor.org.il/cgi-bin/mailman/listinfo/python-il
Oren Tirosh | 11 Jun 15:34 2008
Picon

Re: The Tuples and Lists question

Yes, the only technical difference is that tuples are immutable. For
me that's enough of a raison d'etre for tuples. Indexing dictionaries
by a combination of keys is quite useful. Sets of tuples even more. I
actually used that yesterday.

The other difference is more subtle. When you write 'return x,y' you
think of your function as returning two values, not a single value
that is a sequence of length 2. And when you type 'a, b = b, a' you
think of swapping values, not packing and unpacking of sequences. Not
having to type parentheses in most of these cases helps keep this
illusion and I find that it makes python source code more beautiful.

Beauty matters. Source code is a form of communication with other
human beings. When you use a tuple, the fixed length carries the
implicit connotation that each position has a specific role "first is
x coordinate, second is y". "first is name, second is value", etc.
When your reader sees the square brackets, you are signalling that
"this is a sequence of essentially uniform items. Specific positions
do not carry specific meanings although order might matter. The length
of this list is expected to change between subsequent executions of
the same piece of code or even during the lifetime of the specific
list object".

Oren

On Wed, Jun 11, 2008 at 3:28 PM, Omer Zak <w1 <at> zak.co.il> wrote:
>
> I have a silly question:
> Why does Python have both Tuples and Lists?
>
(Continue reading)

Omer Zak | 11 Jun 16:31 2008
Picon

Re: The Tuples and Lists question

First of all, thanks to those who showed interest in the subject and
replied to my question.

Please consider the following as an academic exercise.  Actually I am
reasonably happy with the current way things are done in Python.  Only
that I am curious to see whether Tuples and Lists could be combined into
a single data type, with some additional behind the curtains processing.

Let's say that it has been decreed that a single data type serve as both
Tuple and List.  How would it be specified and implemented?

First of all, let's use only square brackets [] to represent literals.
The parentheses () will be reserved for function and class method calls.

It may be possible to optionally prefix the brackets with a character
signifying whether the data structure is mutable or not - like the r and
u prefixes of string literals:
  m[1,2,3] - mutable List
  i["a","y","\u2034"] - immutable (would be Tuple in today's Python)

On Wed, 2008-06-11 at 16:03 +0300, Adi Stav wrote:
> I'm not sure what you are suggesting?
> 
> 1. Not having tuples, only lists. And then you wouldn't be able to use lists or tuples as dict keys, and
wouldn't be able to do tuple assignment

Tuple assignments can still be done - instead of considering
  x, y = y, x
as implicit
  (x,y) = (y,x)
(Continue reading)

Omer Zak | 11 Jun 17:33 2008
Picon

Interim summary (was: Re: The Tuples and Lists question)

I asked a question and from the ensuing discussion, it emerges that the
present Pythonic way - of distinguishing among immutable Tuples and
mutable Lists, and providing each with its own syntactical notation - is
fine as is.

The following ideas emerged from the discussion:

1. It would be nice to have an immutable Dict data type, which can be
used as Dict key.

2. It may be nice to explore the concept of different kinds of
references to the same object.  While mutable-expecting references vs.
immutable-expecting references are not useful concepts, the idea of
different kinds of references may be an useful metaphor for controlling
access to values in multi-threaded applications.

3. It is useful to be able to create a value of a mutable class, and
after a while - freeze it i.e. make it a value of the corresponding
immutable class.
For example, if your application needs to create a long Tuple (say, as a
1000-element Tuple serving as a Dict key) and prefers to create it
element by element, then it creates a List and once finished building
the List up, the List is converted into a Tuple.

                                                 --- Omer
--

-- 
Delay is the deadliest form of denial.    C. Northcote Parkinson
My own blog is at http://www.zak.co.il/tddpirate/

My opinions, as expressed in this E-mail message, are mine alone.
(Continue reading)

Ido Abramovich | 11 Jun 17:37 2008
Picon

Re: The Tuples and Lists question

As James Tauber once put it in a blog post:
"the index in a tuple has an implied semantic. The point of a tuple is that the i-th slot means something specific. In other words, it's a index-based (rather than name based) datastructure."
( http://jtauber.com/blog/2006/04/15/python_tuples_are_not_just_constant_lists/ )

It is also mentioned in the same blog post (quoting Phillip Eby) that "Lists are intended to be homogeneous sequences, while tuples are hetereogeneous data structures.".
so you tend to assume that if x is a list then x[0] and x[1] are of the same base class, while you don't make that assumption on tuples.
This is a semantic non-enforced distinction, but it still is a distinction.

Ido.

----- Original Message ----
Fro m: Omer Zak <w1 <at> zak.co.il>
To: Python User Group <python-il <at> hamakor.org.il>
Sent: Wednesday, June 11, 2008 3:28:01 PM
Subject: [Python-il] The Tuples and Lists question

I have a silly question:
Why does Python have both Tuples and Lists?

The only programmer-visible difference, of which I am aware, between
them is that Tuples are immutable and Lists are mutable, with the
following implications:
1. Tuples can be used as hash (Dict) keys, and Lists cannot.
2. When you modify a Tuple, a new Tuple is created.  On the other hand,
List modification happens in place.

I don't see why is the above difference good enough reason to have
different notations for Tuples and Lists.
                                          --- Omer
--
Every good master plan involves building a time machine.  Moshe Zadka
My own blog is at http://www.zak.co.il/tddpirate/

My opinions, as expressed in this E-mail message, are mine alone.
They do not represent the official policy of any organization with which
I may be affiliated in any way.
WARNING TO SPAMMERS:  at http://www.zak.co.il/spamwarning.html

_______________________________________________
Python-il mailing list
Python-il <at> hamakor.org.il
http://hamakor.org.il/cgi-bin/mailman/listinfo/python-il

_______________________________________________
Python-il mailing list
Python-il <at> hamakor.org.il
http://hamakor.org.il/cgi-bin/mailman/listinfo/python-il
Oren Tirosh | 11 Jun 17:46 2008
Picon

Re: The Tuples and Lists question

On Wed, Jun 11, 2008 at 5:31 PM, Omer Zak <w1 <at> zak.co.il> wrote:
>
> First of all, thanks to those who showed interest in the subject and
> replied to my question.
>
> Please consider the following as an academic exercise.  Actually I am
> reasonably happy with the current way things are done in Python.  Only
> that I am curious to see whether Tuples and Lists could be combined into
> a single data type, with some additional behind the curtains processing.

Note that you are going against the current. Python is actually moving
in the direction of having more mutable and immutable variants of
types, not less:

set (mutable), frozenset (immutable)

And in py3k:
bytearray (mutable), bytes (immutable).

> Let's say that it has been decreed that a single data type serve as both
> Tuple and List.  How would it be specified and implemented?
>
> First of all, let's use only square brackets [] to represent literals.
> The parentheses () will be reserved for function and class method calls.

Tuples are constructed with COMMAS, not parentheses!

>>> x = 1, 2
>>> type(x)
<class 'tuple'>
>>> len(  [[1,2,3]]  )
1
>>> len(  ((1,2,3))  )
3

Parentheses mean in Python exactly what they mean in math - order of
precedence. That's why two parens mean the same as one. Parens are
required for disambiguation in certain cases like passing a tuple to a
function but it's the comma that makes the tuple, not the parentheses
(with a special exception for the empty tuple).

> It may be possible to optionally prefix the brackets with a character
> signifying whether the data structure is mutable or not - like the r and
> u prefixes of string literals:
>  m[1,2,3] - mutable List
>  i["a","y","\u2034"] - immutable (would be Tuple in today's Python)

And would these prefixes create instances of a different types or the
same type with a mutability flag? If the former then you have just
changed one syntax for another, which was not your stated intent (type
unification). If the latter, then you have created something with no
precedent anywhere else in Python - a builtin type that magically
changes its behavior.

> >  When you use a tuple, the fixed length carries the
> > implicit connotation that each position has a specific role "first is
> > x coordinate, second is y". "first is name, second is value", etc.
>
> If this is important, then use a class and give names to the positions.

If this was what I wanted I would be writing Java, not Python. A big
part of what I like about Python is its brevity. Not the perlesque
kind of brevity with mystic runes that makes the code less readable =
pythonic brevity makes the code is more readable and yet short enough
to fit into your screen and your mind. In Java you have to define so
many small helper classes that you often can't see the forest for the
trees.

Oren
_______________________________________________
Python-il mailing list
Python-il <at> hamakor.org.il
http://hamakor.org.il/cgi-bin/mailman/listinfo/python-il
Oren Tirosh | 11 Jun 18:02 2008
Picon

Re: Interim summary (was: Re: The Tuples and Lists question)

On Wed, Jun 11, 2008 at 6:33 PM, Omer Zak <w1 <at> zak.co.il> wrote:
> 1. It would be nice to have an immutable Dict data type, which can be
> used as Dict key.

Funny you should mention that...
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/414283

I wrote this recipe a few years ago. I don't expect it to be made into
a builtin, though. The use case is not that common.

> 2. It may be nice to explore the concept of different kinds of
> references to the same object.  While mutable-expecting references vs.
> immutable-expecting references are not useful concepts, the idea of
> different kinds of references may be an useful metaphor for controlling
> access to values in multi-threaded applications.

Python has made the deliberate choice to have types for objects but
not for references. The "consenting adults" principle means there is
no "controlling access" to things and thus no private modifier in
Python.

  Oren
_______________________________________________
Python-il mailing list
Python-il <at> hamakor.org.il
http://hamakor.org.il/cgi-bin/mailman/listinfo/python-il
Adi Stav | 11 Jun 15:03 2008
Picon

Re: The Tuples and Lists question

On Wed, Jun 11, 2008 at 03:28:01PM +0300, Omer Zak wrote:
> I have a silly question:
> Why does Python have both Tuples and Lists?
> 
> The only programmer-visible difference, of which I am aware, between
> them is that Tuples are immutable and Lists are mutable, with the
> following implications:
> 1. Tuples can be used as hash (Dict) keys, and Lists cannot.
> 2. When you modify a Tuple, a new Tuple is created.  On the other hand,
> List modification happens in place.
> 
> I don't see why is the above difference good enough reason to have
> different notations for Tuples and Lists.

I'm not sure what you are suggesting?

1. Not having tuples, only lists. And then you wouldn't be able to use lists or tuples as dict keys, and
wouldn't be able to do tuple assignment

2. Not having lists, only tuples. And then you would be able to use them as dict keys all you want, but you
wouldn't be able to modify their members in place.

3. Have both both tuples and lists, but have a different syntax for handling them than Python currently has.

Which was it?
_______________________________________________
Python-il mailing list
Python-il <at> hamakor.org.il
http://hamakor.org.il/cgi-bin/mailman/listinfo/python-il

Gmane