Re: [Tutor] fnmatch -or glob question

2009-07-03 Thread Kent Johnson
On Fri, Jul 3, 2009 at 8:24 PM, Damon Timm wrote: > And I thought I could just construct something for glob or fnmatch like: > > glob.glob("DSC_0065*.jpg") --or-- fnmatch.fnmatch(file, "DSC_0065*.jpg") Do you have the working directory set to the folder with the jpgs in it? If not, you have to gi

Re: [Tutor] list comprehension problem

2009-07-03 Thread bob gailer
Dinesh B Vadhia wrote: I'm suffering from brain failure (or most likely just being brain less!) and need help to create a list comprehension for this problem: d is a list of integers: d = [0, 8, 4, 4, 4, 7, 2, 5, 1, 1, 5, 11, 11, 1, 6, 3, 5, 6, 11, 1] Want to create a new list that adds the

[Tutor] fnmatch -or glob question

2009-07-03 Thread Damon Timm
Hi - I am trying to find a group of thumbnail files for deletion -- the files all have similar naming structure (though the details vary). When the main file is deleted, I want all the little ones to go too. For example, here is a directory listing: DSC_0063.100.jpg DSC_0063.100x150.jpg DSC_0063

Re: [Tutor] list comprehension problem

2009-07-03 Thread Emile van Sebille
On 7/3/2009 4:19 PM Emile van Sebille said... On 7/3/2009 3:54 PM Dinesh B Vadhia said... As the lists of integers get larger (mine are in the thousands of integers per list) the list comprehension solution will get slower. Do you agree? Yes, no doubt. Your original post asked only if the

Re: [Tutor] list comprehension problem

2009-07-03 Thread Emile van Sebille
On 7/3/2009 3:54 PM Dinesh B Vadhia said... Thanks Emile / Kent. The problem I see with this solution is that at each stage it is re-summing the j's instead of retaining a running total which the 'for-loop' method does ie. >>> dd = [] >>> y = d[0] >>> for i, x in enumerate(d): >>>

Re: [Tutor] list comprehension problem

2009-07-03 Thread Alan Gauld
"Dinesh B Vadhia" wrote As the lists of integers get larger ... the list comprehension solution will get slower. Do you agree? Yes thats why Chris said the linear loop solution is almost certainly faster in this case. However you could speed up the for loop significantly by missing out th

Re: [Tutor] list comprehension problem

2009-07-03 Thread Dinesh B Vadhia
Thanks Emile / Kent. The problem I see with this solution is that at each stage it is re-summing the j's instead of retaining a running total which the 'for-loop' method does ie. >>> dd = [] >>> y = d[0] >>> for i, x in enumerate(d): >>>y += x >>>dd.append(y) As the lists of int

Re: [Tutor] Popen problem with a pipe sign "|"

2009-07-03 Thread Sander Sweers
2009/7/3 hyou : > Hi Sander, > > Thanks for the reply. However, the reason that I have to use subprocess.call > is that if I use > subprocess.Popen, the pipe sign "|" will break the execution of the command > (though I don't know > why). Do you know how can I put "|" correctly in Popen then? (The

Re: [Tutor] list comprehension problem

2009-07-03 Thread Emile van Sebille
On 7/3/2009 1:59 PM Chris Fuller said... The problem with these list comprehensions is that they have O(n**2) complexity. But, the more you work with them the more ease you'll develop at understanding and deploying them. I often find that a (quick) (perhaps complex) list comprehension is

Re: [Tutor] Floor and modulus for complex arguments

2009-07-03 Thread Tim Peters
[Angus Rodgers] > ... > If I started to agitate for changes to a marginal and little-used > feature of the language within days of starting to learn it, might > I not quickly earn a reputation as a crank?  8-P If that's your /goal/, it would be easier to rant about some imagined flaw in the ring o

Re: [Tutor] list comprehension problem

2009-07-03 Thread Chris Fuller
On Friday 03 July 2009 15:37, Emile van Sebille wrote: > On 7/3/2009 1:21 PM Kent Johnson said... > > > On Fri, Jul 3, 2009 at 3:49 PM, Dinesh B > > > > Vadhia wrote: > >> d = [0, 8, 4, 4, 4, 7, 2, 5, 1, 1, 5, 11, 11, 1, 6, 3, 5, 6, 11, 1] > >> > >> and we want: > >> > >> [0, 8, 12, 16, 20, 27, 29,

Re: [Tutor] list comprehension problem

2009-07-03 Thread Emile van Sebille
On 7/3/2009 1:21 PM Kent Johnson said... On Fri, Jul 3, 2009 at 3:49 PM, Dinesh B Vadhia wrote: d = [0, 8, 4, 4, 4, 7, 2, 5, 1, 1, 5, 11, 11, 1, 6, 3, 5, 6, 11, 1] and we want: [0, 8, 12, 16, 20, 27, 29, 34, 35, 36, 41, 52, 63, 64, 70, 73, 78, 84, 95, 96] dd = [ sum(d[:j]) for j in range(len(d

Re: [Tutor] list comprehension problem

2009-07-03 Thread Kent Johnson
On Fri, Jul 3, 2009 at 3:49 PM, Dinesh B Vadhia wrote: > d = [0, 8, 4, 4, 4, 7, 2, 5, 1, 1, 5, 11, 11, 1, 6, 3, 5, 6, 11, 1] > > and we want: > > [0, 8, 12, 16, 20, 27, 29, 34, 35, 36, 41, 52, 63, 64, 70, 73, 78, 84, 95, > 96] > dd = [ sum(d[:j]) for j in range(len(d)) ][1:] > > gives: > > [0, 8, 1

Re: [Tutor] list comprehension problem

2009-07-03 Thread Dinesh B Vadhia
d = [0, 8, 4, 4, 4, 7, 2, 5, 1, 1, 5, 11, 11, 1, 6, 3, 5, 6, 11, 1] and we want: [0, 8, 12, 16, 20, 27, 29, 34, 35, 36, 41, 52, 63, 64, 70, 73, 78, 84, 95, 96] dd = [ sum(d[:j]) for j in range(len(d)) ][1:] gives: [0, 8, 12, 16, 20, 27, 29, 34, 35, 36, 41, 52, 63, 64, 70, 73, 78, 84, 95] Din

Re: [Tutor] Floor and modulus for complex arguments

2009-07-03 Thread Angus Rodgers
>Date: Sat, 04 Jul 2009 00:25:13 +1000 >From: Lie Ryan >Message-ID: > >Angus Rodgers wrote: > >> I /think/ I would be naturally inclined to define: >> >> floor(x + yj) = floor(x) + floor(y)j for all real x, y >> >> z % w = z - floor(z / w) * wfor all complex z, w (!= 0) > >I'm not a m

Re: [Tutor] list comprehension problem

2009-07-03 Thread Emile van Sebille
On 7/3/2009 12:09 PM Dinesh B Vadhia said... I'm suffering from brain failure (or most likely just being brain less!) and need help to create a list comprehension for this problem: d is a list of integers: d = [0, 8, 4, 4, 4, 7, 2, 5, 1, 1, 5, 11, 11, 1, 6, 3, 5, 6, 11, 1] Want to create a n

[Tutor] list comprehension problem

2009-07-03 Thread Dinesh B Vadhia
I'm suffering from brain failure (or most likely just being brain less!) and need help to create a list comprehension for this problem: d is a list of integers: d = [0, 8, 4, 4, 4, 7, 2, 5, 1, 1, 5, 11, 11, 1, 6, 3, 5, 6, 11, 1] Want to create a new list that adds the current number and the pri

Re: [Tutor] Popen problem with a pipe sign "|"

2009-07-03 Thread Sander Sweers
2009/7/3 hyou : > Do you know how can I run the command with | sign correctly with popen? Or > if that’s not possible, can you give me a way to control the output from > subprocess.call? subprocess.call does not support this but subprocess.Popen does. See Doug Hellmann's PMOTW which explains how t

Re: [Tutor] IDLE 3.0 menu weirdness

2009-07-03 Thread Alan Gauld
"Yash" wrote I do not observe the problem on my installation of Python 3.0.1 I don't see any arrows. Also the shortcut keywords work fine Yes the shortcuts worked ok for me too, it was just the menus that were broken. I upgraded to v3.1 and everything is fine now. Definitely odd! Th

[Tutor] Popen problem with a pipe sign "|"

2009-07-03 Thread hyou
Hello, I encountered this problem that when I'm using Popen to execute a DOS command "C:\...\devenv" solution.sln /build "Debug|Win32", it doesn't run anything. However, if I replace "Debug|Win32" with Debug, it works fine. If I use subprocess.call instead, it runs perfectly - however, I canno

Re: [Tutor] window graphics

2009-07-03 Thread David H. Burns
Thanks, I had forgotten the case sensitivity. David ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] window graphics

2009-07-03 Thread David H. Burns
Thanks. I had forgotten the case sensitivity. David ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

[Tutor] Apology (was:When are strings interned?)

2009-07-03 Thread Angus Rodgers
>Date: Fri, 03 Jul 2009 12:46:06 +0100 >From: Angus Rodgers >To: tutor@python.org >Subject: Re: [Tutor] When are strings interned? >Message-ID: >Content-Type: text/plain; charset=us-ascii >[...] >Date: Fri, 03 Jul 2009 14:43:21 +0100 >From: Angus Rodgers >To: tutor@python.org >Subject: Re: [Tuto

Re: [Tutor] window graphics

2009-07-03 Thread Lie Ryan
David H. Burns wrote: > Thanks, Alan, > > With the Python3.0, I have installed, he entry "from tkinter import *" > doesn't produce any error message, but "tk = TK()" results in > "NameError: 'TK' is not defined". Also for the word "canvas" Python is CaSe-SEnsITiVe. TK() is different from Tk() and

Re: [Tutor] window graphics

2009-07-03 Thread Mark Tolonen
"David H. Burns" wrote in message news:4a4d65e5.3040...@cherokeetel.net... Thanks, Alan, With the Python3.0, I have installed, he entry "from tkinter import *" doesn't produce any error message, but "tk = TK()" results in "NameError: 'TK' is not defined". Also for the word "canvas" As yo

Re: [Tutor] When are strings interned?

2009-07-03 Thread Lie Ryan
Angus Rodgers wrote: > Presumably a different optimisation is going on here: > "green ideas" is "green ideas" > True You're correct, there is another layer of optimization, now related to constant string caching. The caching sometimes happens, sometimes not, depending on a very intricate imp

Re: [Tutor] Floor and modulus for complex arguments

2009-07-03 Thread Lie Ryan
Angus Rodgers wrote: > I'm a little confused by: (i) the definition of the modulus and > floor division functions for complex arguments; (ii) the fact > that these functions for complex arguments are now "deprecated"; > and (iii) the fact that the math.floor() function is not defined > at all for

Re: [Tutor] Floor and modulus for complex arguments

2009-07-03 Thread Tim Peters
[Angus Rodgers] > I'm a little confused by: (i) the definition of the modulus and > floor division functions for complex arguments; Perhaps you're confused by the current definitions simply because they don't make good sense. > (ii) the fact that these functions for complex arguments are > now "

Re: [Tutor] When are strings interned?

2009-07-03 Thread Angus Rodgers
This is partly a test to see if I can reply in the correct format to a message in the tutor list (which I receive in digest format). >Date: Thu, 02 Jul 2009 20:39:28 +1000 >From: Lie Ryan > >Angus Rodgers wrote: >[...] > p = "green ideas" > q = "green ideas" > p == q >> True > p i

Re: [Tutor] When are strings interned?

2009-07-03 Thread Angus Rodgers
This is partly a test to see if I can reply in the correct format to a message in the tutor list (which I receive in digest format). >Date: Thu, 02 Jul 2009 20:39:28 +1000 >From: Lie Ryan > >Angus Rodgers wrote: >[...] > p = "green ideas" > q = "green ideas" > p == q >> True > p i

Re: [Tutor] printing tree structure

2009-07-03 Thread Dave Angel
karma wrote: Hi all , I have a nested list in the structure [root,[leftSubtree],[RightSubtree]] that I want to print out. I was thinking that a recursive solution would work here, but so far I can't quite get it working. This is what I have so far: Can someone suggest whether this is suited to

Re: [Tutor] IDLE 3.0 menu weirdness

2009-07-03 Thread Yash
Alan, I do not observe the problem on my installation of Python 3.0.1 (r301:69561, Feb 13 2009, 20:04:18) [MSC v.1500 32 bit (Intel)] on Win Vista or on Win XP SP 3 I don't see any arrows. Also the shortcut keywords work fine and I am able to use the mouse freely. The only problem I get is that

Re: [Tutor] window graphics

2009-07-03 Thread David H. Burns
Thanks, Alan, With the Python3.0, I have installed, he entry "from tkinter import *" doesn't produce any error message, but "tk = TK()" results in "NameError: 'TK' is not defined". Also for the word "canvas" As you suggest, I probably need to start with a 2.x version. ___

[Tutor] Floor and modulus for complex arguments

2009-07-03 Thread Angus Rodgers
I'm a little confused by: (i) the definition of the modulus and floor division functions for complex arguments; (ii) the fact that these functions for complex arguments are now "deprecated"; and (iii) the fact that the math.floor() function is not defined at all for a complex argument. If I were

Re: [Tutor] printing tree structure

2009-07-03 Thread karma
Thanks all for the feedback. As you all rightly pointed out, I was confusing myself by not keeping a track of the recursion depth. Thanks again 2009/7/3 Alan Gauld : > > "karma" wrote > >> thinking that a recursive solution would work here, but so far I can't >> quite get it working. This is wha

Re: [Tutor] printing tree structure

2009-07-03 Thread Alan Gauld
"karma" wrote thinking that a recursive solution would work here, but so far I can't quite get it working. This is what I have so far: Can someone suggest whether this is suited to a recursive solution and Yes certainly if so, what am I doing wrong. L = ['a', ['b',

Re: [Tutor] creating a dict-like class - asigning variables... this one may take some thought ; )

2009-07-03 Thread Lie Ryan
John [H2O] wrote: > > > spir wrote: >> >> What you're looking for is a dictionary... >> s = {"cheese":"Brie", "country":"France", ...} >> >> Or maybe a kind of object type that works ~ like a dict, but with object >> syntax (get rid of {} and "" for keys). Example: >> >> class Stuff(object): >>

Re: [Tutor] printing tree structure

2009-07-03 Thread Lie Ryan
karma wrote: > Hi all , > > I have a nested list in the structure > [root,[leftSubtree],[RightSubtree]] that I want to print out. I was > thinking that a recursive solution would work here, but so far I can't > quite get it working. This is what I have so far: > > Can someone suggest whether this

Re: [Tutor] creating a dict-like class - asigning variables... this one may take some thought ; )

2009-07-03 Thread John [H2O]
spir wrote: > > > What you're looking for is a dictionary... > s = {"cheese":"Brie", "country":"France", ...} > > Or maybe a kind of object type that works ~ like a dict, but with object > syntax (get rid of {} and "" for keys). Example: > > class Stuff(object): > def __iter__(self): >

[Tutor] printing tree structure

2009-07-03 Thread karma
Hi all , I have a nested list in the structure [root,[leftSubtree],[RightSubtree]] that I want to print out. I was thinking that a recursive solution would work here, but so far I can't quite get it working. This is what I have so far: Can someone suggest whether this is suited to a recursive sol