Re: [Tutor] Python command calls the wrong version!

2010-09-08 Thread Alan Gauld
I am new to Python, having perviously used IDL for all my scripts. I was hoping to use Python and so I have just downloaded and installed version 2.6 using the mac installer. That all went fine. I then opened up X11, all fine. Why did you open X11? If you used the Mac installer(*) it shoul

[Tutor] pickling codecs

2010-09-08 Thread Dinesh B Vadhia
I use codecs to retain consistent unicode/utf-8 encoding and decoding for reading/writing to files. Should the codecs be applied when using the pickle/unpickle function? For example, the standard syntax is: # pickle object f = open(object, 'wb') pickle.dump(object, f, 2) # unpickle object f

Re: [Tutor] Code review, plase

2010-09-08 Thread Alex
On Wed, Sep 8, 2010 at 12:20 AM, Steven D'Aprano wrote: > On Wed, 8 Sep 2010 06:39:27 am Alex wrote: >> Hi all. >> >> Could someone review my code? It's the first time I develop a >> reusable module and I would like to have some feedback. >> If you think it's good enough I will package it for pypi

Re: [Tutor] Pastebin.com fork based completely on Python (Django)

2010-09-08 Thread Robert
Does not *look* "Pythonic" - have a look at this : http://paste.pocoo.org/ On Tue, Sep 7, 2010 at 6:00 PM, Carlos Guerrero wrote: > I did a "pastebin.com" fork in Django ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription opti

[Tutor] sort problem

2010-09-08 Thread Roelof Wobben
Hello, I have this : def sort_sequence(seq): """ >>> sort_sequence([3, 4, 6, 7, 8, 2]) [2, 3, 4, 6, 7, 8] >>> sort_sequence((3, 4, 6, 7, 8, 2)) (2, 3, 4, 6, 7, 8) >>> sort_sequence("nothappy") 'ahnoppty' """ if type(seq) == type([]):

Re: [Tutor] sort problem

2010-09-08 Thread Evert Rol
> I have this : > > def sort_sequence(seq): > """ > >>> sort_sequence([3, 4, 6, 7, 8, 2]) > [2, 3, 4, 6, 7, 8] > >>> sort_sequence((3, 4, 6, 7, 8, 2)) > (2, 3, 4, 6, 7, 8) > >>> sort_sequence("nothappy") > 'ahnoppty' > """ >if type(seq) == type([]):

Re: [Tutor] sort problem

2010-09-08 Thread Roelof Wobben
> Subject: Re: [Tutor] sort problem > From: evert@gmail.com > Date: Wed, 8 Sep 2010 17:26:58 +0200 > CC: tutor@python.org > To: rwob...@hotmail.com > > > I have this : > > > > def sort_sequence(seq): > > """ > > >>> sort_sequence([3, 4, 6, 7, 8, 2]) > > [2, 3, 4, 6, 7, 8] > > >>> sort_se

Re: [Tutor] sort problem

2010-09-08 Thread Francesco Loffredo
On 08/09/2010 17.50, Roelof Wobben wrote: > Subject: Re: [Tutor] sort problem > From: evert@gmail.com > Date: Wed, 8 Sep 2010 17:26:58 +0200 > CC: tutor@python.org > To: rwob...@hotmail.com ... > > seq2 = list(seq) > > seq2.sort() > > print seq2 > > seq.join(seq2) > > return seq

Re: [Tutor] sort problem

2010-09-08 Thread Greg
On Wed, Sep 8, 2010 at 11:50 AM, Roelof Wobben wrote: > > > > Subject: Re: [Tutor] sort problem > > From: evert@gmail.com > > Date: Wed, 8 Sep 2010 17:26:58 +0200 > > CC: tutor@python.org > > To: rwob...@hotmail.com > > > > > > I have this : > > > > > > def sort_sequence(seq): > > > """ > > >

Re: [Tutor] sort problem

2010-09-08 Thread Roelof Wobben
Date: Wed, 8 Sep 2010 12:38:03 -0400 From: gregb...@gmail.com To: tutor@python.org Subject: Re: [Tutor] sort problem On Wed, Sep 8, 2010 at 11:50 AM, Roelof Wobben wrote: > Subject: Re: [Tutor] sort problem > From: evert@gmail.com > Date: Wed, 8 Sep 2010 17:26:58 +0200 > CC: tut

Re: [Tutor] sort problem

2010-09-08 Thread bob gailer
On 9/8/2010 1:12 PM, Roelof Wobben wrote: If I understand it right You don't. What does "put two strings into 1 string" mean. Provide an example. What does the documentation say about join? What part of that do you not understand? -- Bob Gailer 919-636-4239 Chapel Hill NC __

Re: [Tutor] sort problem

2010-09-08 Thread Alan Gauld
"Roelof Wobben" wrote > Carefully read the documentation for str.join: > http://docs.python.org/library/stdtypes.html#str.join > >How does it work, what does it return, etc. Then fix the >corresponding line in your code. str.join(iterable)¶ It puts all the elements of iterable into one s

[Tutor] how to create a persistent dictionary w/ cpickle?

2010-09-08 Thread Carter Danforth
Hi, I'm trying to a create a basic addressbook for practice. I'm using a dictionary with cpickle, though I'm not sure how to persistently store each instance in the dictionary. Below is the code I have so far. If I run it once and add a contact and the details, it's fine. p.load(f) shows the detai

Re: [Tutor] sort problem

2010-09-08 Thread Francesco Loffredo
On 08/09/2010 19.12, Roelof Wobben wrote: ... Oke, If I understand it right with join I can put two strings into 1 string. Roelof Not quite. With join you can put together in one string all the elements of a list of strings. While you do so, you can also put another string as a "wall" between e

Re: [Tutor] sort problem

2010-09-08 Thread Francesco Loffredo
On 08/09/2010 19.12, Francesco Loffredo wrote: ... a little example: separator = "Roelof" list = ["Wobben", "Python", "Learner"] print separator.join(list) ... what you will get? Guess before you try. There's more, I forgot to add: print separator This is important, this method *returns* a

Re: [Tutor] sort problem

2010-09-08 Thread Roelof Wobben
Date: Wed, 8 Sep 2010 20:10:28 +0200 From: f...@libero.it To: tutor@python.org Subject: Re: [Tutor] sort problem On 08/09/2010 19.12, Francesco Loffredo wrote: > ... > a little example: > > separator = "Roelof" > list = ["Wobben", "Python", "Learner"] > print separator.join(list) > > ... what

[Tutor] Mutable Properties

2010-09-08 Thread Chris King
Dear Tutors, I noticed that when you use a property to represent a mutable value, I you try to use its methods, it will directly change the value returned. I know this happens because I'm not really assigning it to something new, but changing whats already there, which won't fire off the

Re: [Tutor] Mutable Properties

2010-09-08 Thread Steven D'Aprano
On Thu, 9 Sep 2010 06:59:57 am Chris King wrote: > Dear Tutors, > I noticed that when you use a property to represent a mutable > value, I you try to use its methods, it will directly change the > value returned. I know this happens because I'm not really assigning > it to something new, but

Re: [Tutor] how to create a persistent dictionary w/ cpickle?

2010-09-08 Thread Steven D'Aprano
On Thu, 9 Sep 2010 03:43:42 am Carter Danforth wrote: > Hi, I'm trying to a create a basic addressbook for practice. I'm > using a dictionary with cpickle, though I'm not sure how to > persistently store each instance in the dictionary. Below is the code > I have so far. > > If I run it once and ad

Re: [Tutor] how to create a persistent dictionary w/ cpickle?

2010-09-08 Thread Dave Angel
On 2:59 PM, Carter Danforth wrote: Hi, I'm trying to a create a basic addressbook for practice. I'm using a dictionary with cpickle, though I'm not sure how to persistently store each instance in the dictionary. Below is the code I have so far. If I run it once and add a contact and the details

Re: [Tutor] how to create a persistent dictionary w/ cpickle?

2010-09-08 Thread Alan Gauld
"Carter Danforth" wrote Hi, I'm trying to a create a basic addressbook for practice. I'm using a dictionary with cpickle, though I'm not sure how to persistently store each instance in the dictionary. Below is the code I have so far. If you use a dictionary it makes more sense to use shelv

Re: [Tutor] slicing a string

2010-09-08 Thread Sandip Bhattacharya
On Tue, Sep 7, 2010 at 1:49 PM, Roel Schroeven wrote: > > But remember that you can make it simpler if you simply don't specify > the start and end points: > 'hello'[::-1] > 'olleh' > While I know that idiom works, I haven't really found an explanation as to *why* it works that way. For a s

Re: [Tutor] slicing a string

2010-09-08 Thread Evert Rol
>> But remember that you can make it simpler if you simply don't specify >> the start and end points: >> > 'hello'[::-1] >> 'olleh' >> > > While I know that idiom works, I haven't really found an explanation > as to *why* it works that way. > > For a string S: > * Using range, you need ran

Re: [Tutor] slicing a string

2010-09-08 Thread Sandip Bhattacharya
On Thu, Sep 9, 2010 at 11:34 AM, Evert Rol wrote: > Read > http://docs.python.org/library/stdtypes.html#sequence-types-str-unicode-list-tuple-buffer-xrange > , note 5 (about one "page" down), which explicitly says "If i or j are > omitted or None, they become “end” values (which end depends on the