Re: [Tutor] Kent's top poster script operator.itemgetter()

2009-01-02 Thread Kent Johnson
On Fri, Jan 2, 2009 at 6:12 PM, Sander Sweers wrote: > Hello All, > > While trying to inderstand Kent's script [1] I struggle on the use of > operator.itemgetter(1) from the following piece of code. I understand > it makes it sort on the second value of the counts.iteritems but I do > not understa

[Tutor] check to see if email host has an MX record by using dns.resolve

2009-01-02 Thread Norman Khine
Hi again, I need to check the validity of the email of the user before data is written onto the system. http://paste.lisp.org/display/72986 Is this a correct method to proceed or is there a better solution. Thanks Norman ___ Tutor maillist - Tuto

Re: [Tutor] Better way - fnmatch with list ? CORRECTION

2009-01-02 Thread Jervis Whitley
On Sat, Jan 3, 2009 at 10:48 AM, bob gailer wrote: > bob gailer wrote: >> >> >> for fn in files: >> base, ext = os.path.splitext(fn) >> if ext in ['.flac','.mp3','.m4a']: ## CORRECTION removed * >> >> > for fn in files: base, ext = os.path.splitext(fn) if ext.lower() in ['.flac', '.mp3'

Re: [Tutor] Better way - fnmatch with list ?

2009-01-02 Thread Damon Timm
On Fri, Jan 2, 2009 at 6:44 PM, bob gailer wrote: > Since file is a built-in function it is a good idea to not use it as a > variable name. Oooh! I did not know that ... thanks ... went through and changed them all. > for fn in files: > base, ext = os.path.splitext(fn) > if ext in ['*.flac'

Re: [Tutor] Better way - fnmatch with list ? CORRECTION

2009-01-02 Thread bob gailer
bob gailer wrote: Damon Timm wrote: Hi - am learning Pythong and loving it! Anyhow, what I have works, but I wondered if there was a "better" (more python-y) way. Here is what I am doing with fnmatch ... am thinking there has to be a one-line way to do this with a lambda or list comprehension

Re: [Tutor] Better way - fnmatch with list ?

2009-01-02 Thread bob gailer
Damon Timm wrote: Hi - am learning Pythong and loving it! Anyhow, what I have works, but I wondered if there was a "better" (more python-y) way. Here is what I am doing with fnmatch ... am thinking there has to be a one-line way to do this with a lambda or list comprehension ... but my mind ca

[Tutor] Better way - fnmatch with list ?

2009-01-02 Thread Damon Timm
Hi - am learning Pythong and loving it! Anyhow, what I have works, but I wondered if there was a "better" (more python-y) way. Here is what I am doing with fnmatch ... am thinking there has to be a one-line way to do this with a lambda or list comprehension ... but my mind can't get around it ..

Re: [Tutor] tuple & object's attributes (changed)

2009-01-02 Thread Alan Gauld
"Kent Johnson" wrote To actually *constrain* a collection to be homogeneous seems extremely un-pythonic. In actual fact all containers can hold whatever you want to put in them without restriction (except hashability requirements for sets and dict keys). And strings which are kind of a col

[Tutor] Kent's top poster script operator.itemgetter()

2009-01-02 Thread Sander Sweers
Hello All, While trying to inderstand Kent's script [1] I struggle on the use of operator.itemgetter(1) from the following piece of code. I understand it makes it sort on the second value of the counts.iteritems but I do not understand how operator.itemgetter(1) works. for name, count in sorted(

Re: [Tutor] tuple & object's attributes (changed)

2009-01-02 Thread bob gailer
Kent Johnson wrote: [snip] To actually *constrain* a collection to be homogeneous seems extremely un-pythonic. In actual fact all containers can hold whatever you want to put in them without restriction (except hashability requirements for sets and dict keys). Well, the array module offers o

Re: [Tutor] tuple & object's attributes (changed)

2009-01-02 Thread Andre Engels
On Fri, Jan 2, 2009 at 10:37 PM, Kent Johnson wrote: > Forwarding to the list with comments. > > On Fri, Jan 2, 2009 at 2:47 PM, spir wrote: >> Now, remains one major question: >> Why do lists hold heterogeneous items? (Why did Guido do that choice, and >> then assert that >> lists are for homo

[Tutor] Fw: :initialize a for loop

2009-01-02 Thread ALAN GAULD
Forwarding to list... - Forwarded Message yes i want to clear the images before the next iteration,here is the pseudo code what i want to do a = [ ] for i in range(self.numOne) a.append([i]) to create an empty array, and append the index i to the array and pass this index to gtk im

Re: [Tutor] tuple & object's attributes (changed)

2009-01-02 Thread Kent Johnson
Forwarding to the list with comments. On Fri, Jan 2, 2009 at 2:47 PM, spir wrote: > On Fri, 2 Jan 2009 11:57:32 -0500 > "Kent Johnson" wrote: > >> On Fri, Jan 2, 2009 at 11:10 AM, spir wrote: >> > Can someone explain the following? >> > >> > >> > class Type(object):

Re: [Tutor] format currency

2009-01-02 Thread bob gailer
Norman Khine wrote: Hello, I have this code, is there a better way to get the desired output. http://paste.lisp.org/display/72966 I'd add the variable information e g. ('fr', 'ascii', '%.2f', '%s %s']) to the individual dictionaries. Then all the relevant data is in one place. Then you need

[Tutor] format currency

2009-01-02 Thread Norman Khine
Hello, I have this code, is there a better way to get the desired output. http://paste.lisp.org/display/72966 Thanks ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] object's attributes

2009-01-02 Thread Kent Johnson
On Fri, Jan 2, 2009 at 1:36 PM, Paul McGuire wrote: > The example you cited of creating a thin derived class from object, for the > simple purpose of supporting dynamically assigned attributes, sometimes goes > by the name Bag, from the Smalltalk object framework. Another variation is Bunch, tho

Re: [Tutor] object's attributes

2009-01-02 Thread spir
On Fri, 2 Jan 2009 12:36:42 -0600 "Paul McGuire" wrote: > Denis - Hello Paul, pleased to read you again ;-) > What you are seeing is standard procedure for any built-in type - no dynamic > assignment of attributes allowed. Here is an analogous case to your > example, but based on str instead

Re: [Tutor] object's attributes

2009-01-02 Thread Paul McGuire
Denis - What you are seeing is standard procedure for any built-in type - no dynamic assignment of attributes allowed. Here is an analogous case to your example, but based on str instead of object: greeting = "bon jour" greeting.language = "French" # raises AttributeError: 'str' object has no a

Re: [Tutor] List of dictionaries membership test

2009-01-02 Thread Alan Gauld
"Norman Khine" wrote >>> currencies = [{'sign': '\xe2\x82\xac', 'id': 'EUR', >>> 'is_selected': False, 'title': 'EURO'}, {'sign': '\xc2\xa3', 'id': 'GBP', 'is_selected': True, 'title': 'Pound'}, {'sign': '$', 'id': 'USD', 'is_selected': False, 'title': 'Dollar'}] What is the simplest way t

Re: [Tutor] object's attributes

2009-01-02 Thread Kent Johnson
On Fri, Jan 2, 2009 at 11:10 AM, spir wrote: > Can someone explain the following? > > > class Type(object): >pass > o = Type() > o.a = 1 > print o, o.a > print dir(object) > ==> ['__class__', '__delattr__', '__doc__', '__getattribute__', '__hash__', > '__init_

Re: [Tutor] object's attributes

2009-01-02 Thread Alan Gauld
"spir" wrote Can someone explain the following? Not really an explanation but I did notice when repeating your experiment that your class instance has a __dict__ attribute but object does not. The new attribute a is apparently located in the dict. class C(object): pass ... o = object() c

Re: [Tutor] :initialize a for loop

2009-01-02 Thread Alan Gauld
"i i" wrote in self.numOne = random.randint(1,10) for i in range(self.numOne): self.image = gtk.Image() self.image.set_from_file("./Pink-Flower-32x32.png") self.fixed.put(self.image, i*25, 0) self.image.show() images,i want to initialize the array or empt

Re: [Tutor] Distinction between tuples and lists

2009-01-02 Thread Alan Gauld
"Roel Schroeven" wrote In the point of view taken by Guido and the writer of the blogs mentioned before, a tuple of x, y coordinates is not homogeneous, it's heterogeneous. Both x and y do have the same type, but that's not the point. The point is that the meaning of the two elements is diff

[Tutor] object's attributes

2009-01-02 Thread spir
Can someone explain the following? class Type(object): pass o = Type() o.a = 1 print o, o.a print dir(object) ==> ['__class__', '__delattr__', '__doc__', '__getattribute__', '__hash__', '__init__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setat

Re: [Tutor] List of dictionaries membership test

2009-01-02 Thread Kent Johnson
On Fri, Jan 2, 2009 at 8:17 AM, Norman Khine wrote: > Hello, > I have this list > currencies = [{'sign': '\xe2\x82\xac', 'id': 'EUR', 'is_selected': False, 'title': 'EURO'}, {'sign': '\xc2\xa3', 'id': 'GBP', 'is_selected': True, 'title': 'Pound'}, {'sign': '$', 'id': 'USD', 'is_sele

Re: [Tutor] Top posters to tutor list for 2008

2009-01-02 Thread Kent Johnson
On Fri, Jan 2, 2009 at 8:13 AM, Sander Sweers wrote: > On Fri, Jan 2, 2009 at 13:52, Kent Johnson wrote: >> Or ask more questions, that works too! > > So you and Alan ask the most questions ;-) No, that honor goes to Dick Moores. He is in the top 10 in 4 of the last 5 years! > Thanks to all the

Re: [Tutor] Distinction between tuples and lists

2009-01-02 Thread Roel Schroeven
Alan Gauld schreef: > "Kent Johnson" wrote >> For what it's worth, Guido has explicitly said, >> "Tuples are for heterogeneous data, list are for homogeneous data. >> Tuples are *not* read-only lists." > > That surprises me, he has always seemed more pragmatist than purist. > However even Guido s

[Tutor] List of dictionaries membership test

2009-01-02 Thread Norman Khine
Hello, I have this list >>> currencies = [{'sign': '\xe2\x82\xac', 'id': 'EUR', 'is_selected': False, 'title': 'EURO'}, {'sign': '\xc2\xa3', 'id': 'GBP', 'is_selected': True, 'title': 'Pound'}, {'sign': '$', 'id': 'USD', 'is_selected': False, 'title': 'Dollar'}] What is the simplest way to e

Re: [Tutor] Top posters to tutor list for 2008

2009-01-02 Thread Sander Sweers
On Fri, Jan 2, 2009 at 13:52, Kent Johnson wrote: > Or ask more questions, that works too! So you and Alan ask the most questions ;-) Seriously now, this really shows the power of Python and I'll have a good time figuring out how this exactly works. Thanks to all the Tutors for year of great su

Re: [Tutor] Top posters to tutor list for 2008

2009-01-02 Thread Kent Johnson
On Fri, Jan 2, 2009 at 5:34 AM, Alan Gauld wrote: > I think the figures reflect the general level of activity on the list. > We seem to have peaked in 2005... > Statistics, don't you love 'em :-) I couldn't resist adding a total number of posts and percent to the calculations. Statistics + pytho

Re: [Tutor] Top posters to tutor list for 2008

2009-01-02 Thread Kent Johnson
On Fri, Jan 2, 2009 at 2:06 AM, Luke Paireepinart wrote: > Yeah, I agree. Interesting script, Kent. Surprisingly short. > > I didn't realize I wasn't in the top 5 posters for 2008! I guess I > have a new year's resolution to be more helpful. Or ask more questions, that works too! Kent

[Tutor] :initialize a for loop

2009-01-02 Thread i i
Hi, i am making an activity in glade.here is the code self.numOne = random.randint(1,10) for i in range(self.numOne): self.image = gtk.Image() self.image.set_from_file("./Pink-Flower-32x32.png") self.fixed.put(self.image, i*25, 0) self.image.sh

Re: [Tutor] Inserting one dictionary into another

2009-01-02 Thread spir
On Thu, 01 Jan 2009 11:04:42 -0500 "Keith Reed" wrote: > I'm having trouble assigning a dictionary as a value within another: > > > Code Snippet Start > > for line in fromchild.readlines(): > itemarray = line.strip().split(":") > parent

Re: [Tutor] Top posters to tutor list for 2008

2009-01-02 Thread Alan Gauld
"Kent Johnson" wrote that generates it. The lists for previous years (back to 2003) are at the end so everyone on the list doesn't hit the archives to find out Alan, I thought you might have passed me this year but we are both off a little :-) I think the figures reflect the general lev