Re: [Tutor] Sorting a list

2009-05-13 Thread spir
Le Wed, 13 May 2009 23:12:29 +0530, Ataulla S H s'exprima ainsi: > >>> k = [each for each in l if type(each) == type(int())] You can write "int" (is a type since py 2.2, I guess). assert int==type(int()) # ok Denis -- la vita e estrany ___

Re: [Tutor] Sorting a list

2009-05-13 Thread Ataulla S H
>>> l = [4, 6, 'word','a', 3, 9] >>> l.sort() >>> l [3, 4, 6, 9, 'a', 'word'] >>> k = [each for each in l if type(each) == type(int())] >>> k [3, 4, 6, 9] >>> kex = [each for each in l if type(each) != type(int())] >>> kex ['a', 'word'] >>> kex+k ['a', 'word', 3, 4, 6, 9] On Wed, May 13, 2009 at

Re: [Tutor] Sorting a list

2009-05-13 Thread Alan Gauld
"vince spicer" wrote def compare(x,y): try: return cmp(int(x), int(y)) except: pass try: int(x) except: return -1 try: int(y) except: return 1 return 0 Or def compare(x,y): if type(x) == str: return -1 if type(y) == s

Re: [Tutor] saveing and loading text data

2009-05-13 Thread Alan Gauld
"Jacob Mansfield" wrote hi everyone, I'm a bit new here but i was wondering if someone could check some of my code, it's not doing quite what it's meant to. That's not very specific. What is it meant to do? What does it actually do? Do you get any error messages? If so post them in the emai

Re: [Tutor] Sorting a list

2009-05-13 Thread vince spicer
you can pass sort a custom compare function Simple ex: def compare(x,y): try: return cmp(int(x), int(y)) except: pass try: int(x) except: return -1 try: int(y) except: return 1 return 0 x = [4, 6, 'word', 3, 9] x.sort(

Re: [Tutor] Sorting a list

2009-05-13 Thread Emile van Sebille
On 5/13/2009 9:25 AM Timo said... Hello, I don't think this should be difficult, so maybe I look over it. But I can't seem to find the solution. I have a list with one word and a couple of numbers. If this is always the case you can use the sort method of lists, then relocate the last entr

[Tutor] Sorting a list

2009-05-13 Thread Timo
Hello, I don't think this should be difficult, so maybe I look over it. But I can't seem to find the solution. I have a list with one word and a couple of numbers. Now I want the word to be kept in the first location and the numbers to be sorted. So this: [4, 6, 'word', 3, 9] should be: [

Re: [Tutor] cannot subclass imported type

2009-05-13 Thread spir
Le Wed, 13 May 2009 08:40:25 -0700, Emile van Sebille s'exprima ainsi: > On 5/13/2009 8:32 AM spir said... > > Hello, > > > > I wanted to subclass the type Window of pyGTK for main app windows (for > > the obvious reason that they always contain the same init and end code) > > and run into an un

Re: [Tutor] cannot subclass imported type

2009-05-13 Thread Emile van Sebille
On 5/13/2009 8:32 AM spir said... Hello, I wanted to subclass the type Window of pyGTK for main app windows (for the obvious reason that they always contain the same init and end code) and run into an unexpected problem: = import pygtk pygtk.require('2.0') import gt

[Tutor] cannot subclass imported type

2009-05-13 Thread spir
Hello, I wanted to subclass the type Window of pyGTK for main app windows (for the obvious reason that they always contain the same init and end code) and run into an unexpected problem: = import pygtk pygtk.require('2.0') import gtk # debug output print gtk print gtk

Re: [Tutor] saveing and loading text data

2009-05-13 Thread Christian Witts
Jacob Mansfield wrote: hi everyone, I'm a bit new here but i was wondering if someone could check some of my code, it's not doing quite what it's meant to. the problem is when you start the application again and enter the databox.txt to load from thanks Databox_2_0.py: import sys, os pyga

Re: [Tutor] (a, b) = (l[0:2], l[2:])

2009-05-13 Thread Alan Gauld
"Jabin Jezreel" wrote What is the idiomatic way to write the right side of (a, b) = (l[0:2], l[2:]) ? (not worried about the parens, just the splitting of the sequence) I think you have it. I'm not aware of any better way. -- Alan Gauld Author of the Learn to Program web site http://www

[Tutor] saveing and loading text data

2009-05-13 Thread Jacob Mansfield
hi everyone, I'm a bit new here but i was wondering if someone could check some of my code, it's not doing quite what it's meant to. the problem is when you start the application again and enter the databox.txt to load from thanks Databox_2_0.py: import sys, os pygame.init() def load(filename):

Re: [Tutor] Retrieving Data from Pmw.EntryFeild

2009-05-13 Thread Alan Gauld
"Sampath Girish" wrote Ok Now i have one more target to reach. I need to add 1st and 3rd fields in both the rows and place it in fourth column. Can u give me any example? Can you explain what you mean? You mentioned earlier a 3x3 matrix of entry fields. So you already have a 1st field a

Re: [Tutor] (a, b) = (l[0:2], l[2:])

2009-05-13 Thread Christian Witts
Jabin Jezreel wrote: What is the idiomatic way to write the right side of (a, b) = (l[0:2], l[2:]) ? (not worried about the parens, just the splitting of the sequence) ___ Tu

Re: [Tutor] (a, b) = (l[0:2], l[2:])

2009-05-13 Thread Lie Ryan
Jabin Jezreel wrote: What is the idiomatic way to write the right side of (a, b) = (l[0:2], l[2:]) ? (not worried about the parens, just the splitting of the sequence) that way is fine. Although usually it don't use parens and 0 is omitted... a, b = l[:2], l[2:] In python, direct index a

Re: [Tutor] simply moving files]]

2009-05-13 Thread Kent Johnson
On Wed, May 13, 2009 at 3:58 AM, Alan Gauld wrote: > or for platform independance: > > os.sep.join([src,fnames]) or os.path.join(src, fnames) Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Retrieving Data from Pmw.EntryFeild

2009-05-13 Thread Sampath Girish
Ok Now i have one more target to reach. I need to add 1st and 3rd fields in both the rows and place it in fourth column. Can u give me any example? On Tue, May 12, 2009 at 7:51 PM, Kent Johnson wrote: > On Tue, May 12, 2009 at 9:48 AM, Sampath Girish > wrote: > > Thank you Mr Kent for givin

[Tutor] (a, b) = (l[0:2], l[2:])

2009-05-13 Thread Jabin Jezreel
What is the idiomatic way to write the right side of (a, b) = (l[0:2], l[2:]) ? (not worried about the parens, just the splitting of the sequence) ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Calling method in parent class

2009-05-13 Thread Jeremiah Dodds
On Wed, May 13, 2009 at 10:00 AM, Alan Gauld wrote: > > I may be coming across a bit strong on this one but it is such a > fundamentally important feature of OOP that I feel on a list like tutor > it is important to make it clear that this is not only correct behaviour > but is very common in prac

Re: [Tutor] Calling method in parent class

2009-05-13 Thread Jeremiah Dodds
On Wed, May 13, 2009 at 9:44 AM, spir wrote: > > > Then someone stated that, except for __init__, this should be considered > wrong. You and Kent disagreed (and indeed I do too). Yup, that was me. I was incorrect, and am now searching around for writings on proper OOP design with a python slant

Re: [Tutor] Calling method in parent class

2009-05-13 Thread Alan Gauld
"spir" wrote But calling the method of a superclass from the same method is very, very common. Yep, for sure; and I was not discussing this actually. (1) In fact, the whole exchange started when the OP asked how to call 2 different methods on the same object, one beeing defined on on its ow

Re: [Tutor] Calling method in parent class

2009-05-13 Thread spir
Le Tue, 12 May 2009 23:23:02 +0100, "Alan Gauld" s'exprima ainsi: > But calling the method of a superclass from the same method is very, > very common. [...] Yep, for sure; and I was not discussing this actually. (1) In fact, the whole exchange started when the OP asked how to call 2 different

Re: [Tutor] simply moving files]]

2009-05-13 Thread David
Alan Gauld wrote: "David" wrote Forwarded to the list, I would also like to understand the forward slash; os.system("mv %s/%s %s" % (src, fnames, dst)) The slash separates the file path, src, from the filename. Thus if src is /foo/bar/baz and fnames is spam then %s/%s becomes /foo/bar/b

Re: [Tutor] simply moving files]]

2009-05-13 Thread Alan Gauld
"David" wrote Forwarded to the list, I would also like to understand the forward slash; os.system("mv %s/%s %s" % (src, fnames, dst)) The slash separates the file path, src, from the filename. Thus if src is /foo/bar/baz and fnames is spam then %s/%s becomes /foo/bar/baz/spam Another wa