Re: [Tutor] creating a tab delimited filename

2005-03-16 Thread C Smith
Hi Jacob, Watch out with your code, ### if i==1000: i=0 else: i=i+1 ### Since this test is done after you have stored your data you are actually going to store 1001 pieces of data. i starts at 0 you store 0 you do your test and i is incremented {that's set 1} i is 1 you store

[Tutor] Re: Convert doesn't work... I'm stumped

2005-03-16 Thread Javier Ruere
Jacob S. wrote: I've tried doc string testing with doctest, but I find I can do better just using the interactive interpreter. Do better? With doctest you protect yourself from future bugs. How can you do better just using the interpreter? Mr. Johnson has already pointed out how to make doctes

Re: [Tutor] stopping greedy matches

2005-03-16 Thread Kent Johnson
Mike Hall wrote: Liam, "re.compile("in (.*?)\b")" will not find any match in the example string I provided. I have had little luck with these non-greedy matchers. "in (.*?)\b" will match against "in " because you use .* which will match an empty string. Try "in (.+?)\b" (or "(?<=\bin)..+?\b" )to

Re: [Tutor] Re: Convert doesn't work... I'm stumped

2005-03-16 Thread Kent Johnson
Jacob S. wrote: Ahh... I found that out today. A little more rest, I guess. As for unit testing, I've seen it used, but I've never implemented it. I've tried doc string testing with doctest, but I find I can do better just using the interactive interpreter. I think one way to use doctest is to cop

Re: [Tutor] stopping greedy matches

2005-03-16 Thread Christopher Weimann
On 03/16/2005-12:12PM, Mike Hall wrote: > I'm having trouble getting re to stop matching after it's consumed > what I want it to. Using this string as an example, the goal is to > match "CAPS": > > >>> s = "only the word in CAPS should be matched" > jet% python Python 2.4 (#2, Jan 5 2005,

Re: [Tutor] Re: Convert doesn't work... I'm stumped

2005-03-16 Thread Jacob S.
Ahh... I found that out today. A little more rest, I guess. As for unit testing, I've seen it used, but I've never implemented it. I've tried doc string testing with doctest, but I find I can do better just using the interactive interpreter. (I don't know why. Impatience I guess. Maybe I just want

Re: [Tutor] Convert doesn't work... I'm stumped

2005-03-16 Thread Jacob S.
Oh, god!! I found my problem... I was using the inverses incorrectly -- in Advanced Calculus and I can't even do algebra correctly. To make a long story short, in the second functions I was putting the x in the denominator when it needs to be in the numerator... But! Your post is not in vain, D

Re: [Tutor] stopping greedy matches

2005-03-16 Thread Mike Hall
On Mar 16, 2005, at 5:32 PM, Sean Perry wrote: I know this does not directly help, but I have never successfully used \b in my regexs. I always end up writing something like foo\s+bar or something more intense. I've had luck with the boundary flag in relation to lookbehinds. For example, if I wa

Re: [Tutor] stopping greedy matches

2005-03-16 Thread Mike Hall
Liam, "re.compile("in (.*?)\b")" will not find any match in the example string I provided. I have had little luck with these non-greedy matchers. I don't appear to have redemo.py on my system (on OSX), as an import returns an error. I will look into finding this module, thanks for pointing me

Re: [Tutor] stopping greedy matches

2005-03-16 Thread Liam Clarke
> >>> x=re.compile(r"(?<=\bin).+\b") Try >>> x = re.compile("in (.*?)\b") .*? is a non-greedy matcher I believe. Are you using python24/tools/scripts/redemo.py? Use that to test regexes. Regards, Liam Clarke On Wed, 16 Mar 2005 12:12:32 -0800, Mike Hall <[EMAIL PROTECTED]> wrote: > I'm hav

Re: [Tutor] Newbie in Python (fwd)

2005-03-16 Thread Liam Clarke
Oh and > listFile = a #listFile is a list that holds the name >of #files #print listFile, I don't know what errors you're getting but considering this - #listFile[a] +=1 I can see what you're trying to do. So, we have this code: for a in mainFolder: #do some stuff listFile = a

Re: [Tutor] Newbie in Python (fwd)

2005-03-16 Thread Liam Clarke
Hi Oscar, processing emails... you want to use the email module. I believe, you'd go like this (and this is rough, and untested, docs are http://docs.python.org/lib/node565.html) >>>import email >>>parser = email.HeaderParser() >>> msgFile = file('email.txt','r') >>> msgObj = parser.parse(ms

[Tutor] stopping greedy matches

2005-03-16 Thread Mike Hall
I'm having trouble getting re to stop matching after it's consumed what I want it to. Using this string as an example, the goal is to match "CAPS": >>> s = "only the word in CAPS should be matched" So let's say I want to specify when to begin my pattern by using a lookbehind: >>> x = re.compile

Re: [Tutor] How to delete a class instance

2005-03-16 Thread Shitiz Bansal
--- Danny Yoo <[EMAIL PROTECTED]> wrote: > Ok, this makes sense. Each passenger thread needs > to know about the > queue, because that's the place you want the > passenger to drop out of. > > Lists support a 'remove()' method, so you may be > able to use it. Does it operate like queue.remove(s

[Tutor] Image manipulation

2005-03-16 Thread Ertl, John
All, I have an image with a bunch of white space that I need to crop. I would like to automate the process using python and I was wondering what is the best module for image manipulation? I have seen PIL and Python magic what is recommended? John Ertl _

Re: [Tutor] How to delete a class instance

2005-03-16 Thread Kent Johnson
Shitiz Bansal wrote: In the code you have shown, I don't see any need for the queue. Just create the thread and start it. I don't think you have to keep a reference to it. I'm not sure, but I think the thread will be garbage collected when it completes. (Can anyone else confirm this?) This does

Re: [Tutor] How to delete a class instance

2005-03-16 Thread Danny Yoo
> --- Danny Yoo <[EMAIL PROTECTED]> wrote: > > > Ok, this makes sense. Each passenger thread needs to know about the > > queue, because that's the place you want the passenger to drop out of. > > > > Lists support a 'remove()' method, so you may be able to use it. > > Does it operate like queue.

Re: [Tutor] How to delete a class instance

2005-03-16 Thread Shitiz Bansal
> In the code you have shown, I don't see any need for > the queue. Just create the thread and start it. > I don't think you have to keep a reference to it. > I'm not sure, but I think the thread will be > garbage collected when it completes. (Can anyone > else confirm this?) This does make se

Re: [Tutor] How to delete a class instance

2005-03-16 Thread Kent Johnson
Shitiz Bansal wrote: No, this list is not a linked list. Since mu original code is rather huge, I am presenting the relevant snippet. queue=[] def genpassenger(num,destination,queue=queue): for i in range(num): newpass=passenger(destination) queue.append(newpass) newpass

Re: [Tutor] How to delete a class instance

2005-03-16 Thread Danny Yoo
On Wed, 16 Mar 2005, Shitiz Bansal wrote: > No, this list is not a linked list. > Since mu original code is rather huge, I am presenting > the relevant snippet. > queue=[] > def genpassenger(num,destination,queue=queue): > for i in range(num): > newpass=passenger(destination) >

RE: [Tutor] Newbie in Python (fwd)

2005-03-16 Thread Danny Yoo
[Forwarding to [EMAIL PROTECTED] Oscar, when you reply next time, please use your email client's Reply-to-all feature. Otherwise, no one else will see the message.] -- Forwarded message -- Date: Wed, 16 Mar 2005 23:03:13 +1100 From: oscar ng <[EMAIL PROTECTED]> To: 'Danny Yoo'

Re: [Tutor] How to delete a class instance

2005-03-16 Thread Shitiz Bansal
No, this list is not a linked list. Since mu original code is rather huge, I am presenting the relevant snippet. queue=[] def genpassenger(num,destination,queue=queue): for i in range(num): newpass=passenger(destination) queue.append(newpass) newpass.start() class passen

Re: Fwd: [Tutor] creating a tab delimited filename

2005-03-16 Thread Kent Johnson
Max Noel wrote: Forwarding to the list -- please use Reply to All. Begin forwarded message: From: jrlen balane <[EMAIL PROTECTED]> Date: March 16, 2005 04:13:40 GMT To: Max Noel <[EMAIL PROTECTED]> Subject: Re: [Tutor] creating a tab delimited filename Reply-To: jrlen balane <[EMAIL PROTECTED]> why

Fwd: [Tutor] creating a tab delimited filename

2005-03-16 Thread Max Noel
Forwarding to the list -- please use Reply to All. Begin forwarded message: From: jrlen balane <[EMAIL PROTECTED]> Date: March 16, 2005 04:13:40 GMT To: Max Noel <[EMAIL PROTECTED]> Subject: Re: [Tutor] creating a tab delimited filename Reply-To: jrlen balane <[EMAIL PROTECTED]> why is this not wor

Re: [Tutor] How to delete a class instance

2005-03-16 Thread Kent Johnson
Shitiz Bansal wrote: Hi, How do i delete a class instance in a function running within itself? All the instances of the class are stored in a list, and they need to be deleted after executing their function. However since the list is dynamic, there is no way to know the exact position of the instan

[Tutor] How to delete a class instance

2005-03-16 Thread Shitiz Bansal
Hi, How do i delete a class instance in a function running within itself? All the instances of the class are stored in a list, and they need to be deleted after executing their function. However since the list is dynamic, there is no way to know the exact position of the instance within the list.

Re: [Tutor] Convert doesn't work... I'm stumped

2005-03-16 Thread Danny Yoo
> > A table that stores a similar amount of information might be something > like this: > > ### > meterRatios = { 'm' : D(1), ## 1 meter == 1 meter > 'km' : D(1000),## 1000 meters == 1 kilometer > 'cm' : D(1)/D(100),## .001 meters == 1 c

Re: [Tutor] Convert doesn't work... I'm stumped

2005-03-16 Thread Danny Yoo
On Tue, 15 Mar 2005, Jacob S. wrote: > Okay, not a very descriptive subject, but here goes... > > This is the code Hi Jacob, > from decimal import Decimal as D Ok, I think I see why you're using this, but you have to be aware that the decimal module itself is susceptible to imprecision: