Re: [Tutor] str.split and quotes

2005-04-11 Thread Alberto Troiano
Gotcha!! I'll try it with my app and let you know how it went Thanks Alberto  Gaucho>From: Kent Johnson <[EMAIL PROTECTED]> >CC: tutor@python.org >Subject: Re: [Tutor] str.split and quotes >Date: Mon, 11 Apr 2005 16:55:22 -0400 > >Alberto Troiano wrote: >&g

Re: [Tutor] str.split and quotes

2005-04-11 Thread Kent Johnson
Alberto Troiano wrote: Thanks Kent but now I need you to explain me the code :( That code won't work for you. It is for timing how long it takes to do something, not for generating repeated events. To give you a graphic example how can make this function to run every 5 seconds def foo(): pr

Re: [Tutor] str.split and quotes

2005-04-11 Thread Alberto Troiano
gards Alberto>From: Kristian Zoerhoff <[EMAIL PROTECTED]> >Reply-To: Kristian Zoerhoff <[EMAIL PROTECTED]> >To: Alberto Troiano <[EMAIL PROTECTED]> >CC: [EMAIL PROTECTED], tutor@python.org >Subject: Re: [Tutor] str.split and quotes >Date: Mon, 11 Apr 2005 11:03:13 -

Re: [Tutor] str.split and quotes

2005-04-11 Thread Kristian Zoerhoff
On Apr 11, 2005 11:03 AM, Kristian Zoerhoff <[EMAIL PROTECTED]> wrote: > while true: > foo() > time.sleep(5) Err, make that while True: Note to self: test before posting. -- Kristian kristian.zoerhoff(AT)gmail.com zoerhoff(AT)freeshell.org _

Re: [Tutor] str.split and quotes

2005-04-11 Thread Kristian Zoerhoff
On Apr 11, 2005 11:00 AM, Alberto Troiano <[EMAIL PROTECTED]> wrote: > > To give you a graphic example how can make this function to run every 5 > seconds > > def foo(): > > print "Hello world!" > I'm not Kent, but I play him on TV ;-) import time def foo(): print "Hello world!"

Re: [Tutor] str.split and quotes

2005-04-11 Thread Alberto Troiano
PROTECTED]> >Subject: Re: [Tutor] str.split and quotes >Date: Sat, 09 Apr 2005 11:37:56 -0400 > >Alberto Troiano wrote: >>Where and How can I see the post you make?? > >In the list archives >http://mail.python.org/pipermail/tutor/2005-April/037362.html > >K

Re: [Tutor] str.split and quotes

2005-04-09 Thread Kent Johnson
Alberto Troiano wrote: Sorry to bother you that much. I know I have a lot to learn yet but I hope you can teach me. I see that someone posted something about running functions with a timer. How can I do this??? You can use the timeit module, see my recent post for an example. You can also use ti

Re: [Tutor] str.split and quotes

2005-04-09 Thread Alberto Troiano
fresh themself until the sleep goes off. Thanks in advanced for the help Alberto>From: Kent Johnson <[EMAIL PROTECTED]> >CC: tutor@python.org >Subject: Re: [Tutor] str.split and quotes >Date: Sat, 09 Apr 2005 07:45:27 -0400 > >[EMAIL PROTECTED] wrote: >>I was glad to see

Re: [Tutor] str.split and quotes

2005-04-09 Thread Kent Johnson
[EMAIL PROTECTED] wrote: I was glad to see your post showing how to run a list of functions through the timer. That's a nice way to do it! You better slip some square brackets into your definition of d though: d = dict( [((i,i,i), i) for i in range(1000)]) In Python 2.4 they are not nee

Re: [Tutor] str.split and quotes

2005-04-09 Thread smiles
Kent Johnson wrote: Marilyn Davis wrote:> Is there a reason to prefer one over the other?  Is one faster?  I > compiled my regular _expression_ to make it quicker. The only way to know which is faster is to time them both. The timeit module makes it pretty easy to do this.Here is a simple example

Re: [Tutor] str.split and quotes

2005-04-08 Thread Marilyn Davis
On Fri, 8 Apr 2005, C Smith wrote: > Tony wrote: > With Python 2.4 I get these results (all imports are factored > out, all give > the same result except for CSV which strips the "s) with > timeit.py: > > Just a note here in terms of results.  Although the results are all

Re: [Tutor] str.split and quotes

2005-04-08 Thread C Smith
Tony wrote: With Python 2.4 I get these results (all imports are factored out, all givethe same result except for CSV which strips the "s) with timeit.py: Just a note here in terms of results.  Although the results are all the same and they work for the case where there is single quoted phrase wit

Re: [Tutor] str.split and quotes

2005-04-08 Thread Marilyn Davis
On Fri, 8 Apr 2005, Kent Johnson wrote: > Marilyn Davis wrote: > > Is there a reason to prefer one over the other? Is one faster? I > > compiled my regular expression to make it quicker. > > The only way to know which is faster is to time them both. The timeit module > makes it pretty easy to

Re: [Tutor] str.split and quotes

2005-04-08 Thread Kent Johnson
Marilyn Davis wrote: Is there a reason to prefer one over the other? Is one faster? I compiled my regular expression to make it quicker. The only way to know which is faster is to time them both. The timeit module makes it pretty easy to do this. Here is a simple example of using timeit for a d

RE: [Tutor] str.split and quotes

2005-04-07 Thread Tony Meyer
> Wow Tony. That is so generous of you to do this experiment. > It must be a great re engine. It really wasn't much effort - just copying & pasting it all together and throwing in a few timeit statements. The timeit module is another great thing about Python :) > "Obvious" doesn't mean we can

Re: [Tutor] str.split and quotes

2005-04-07 Thread Tim Peters
[Tony Meyer] ... >> Somewhat ironically, one of the tenets of Python is "there should be one-- >> and preferably only one --obvious way to do it." (type "import this" at an [Marilyn Davis] > In this case, there is: regular expressions. :^) > > "Obvious" doesn't mean we can, necessarily, all see i

RE: [Tutor] str.split and quotes

2005-04-07 Thread Marilyn Davis
On Fri, 8 Apr 2005, Tony Meyer wrote: > > Is there a reason to prefer one over the other? Is one > > faster? I compiled my regular expression to make it quicker. > > With Python 2.4 I get these results (all imports are factored out, all give > the same result except for CSV which strips the "s)

RE: [Tutor] str.split and quotes

2005-04-07 Thread Tony Meyer
> Is there a reason to prefer one over the other? Is one > faster? I compiled my regular expression to make it quicker. With Python 2.4 I get these results (all imports are factored out, all give the same result except for CSV which strips the "s) with timeit.py: Own split: 26.8668364275 Toke

Re: [Tutor] str.split and quotes

2005-04-07 Thread Danny Yoo
> > I'm not sure if this is appropriate for Marilyn's purposes though, but > > I thought I might just toss it out. *grin* > > Thank you Danny. Very interesting. Both approaches are perfect for > me. > > Is there a reason to prefer one over the other? Is one faster? I > compiled my regular expr

Re: [Tutor] str.split and quotes

2005-04-07 Thread Marilyn Davis
On Thu, 7 Apr 2005, Danny Yoo wrote: > > > On Wed, 6 Apr 2005, Kent Johnson wrote: > > > s = 'Hi "Python Tutors" please help' > > s.split() > > > > > > ['Hi', '"Python', 'Tutors"', 'please', 'help'] > > > > > > > > > I wish it would leave the stuff in quotes in tact: > > > > > > ['Hi',

Re: [Tutor] str.split and quotes

2005-04-07 Thread Danny Yoo
On Wed, 6 Apr 2005, Kent Johnson wrote: > s = 'Hi "Python Tutors" please help' > s.split() > > > > ['Hi', '"Python', 'Tutors"', 'please', 'help'] > > > > > > I wish it would leave the stuff in quotes in tact: > > > > ['Hi', '"Python Tutors"', 'please', 'help'] > > You can do this easily

Re: [Tutor] str.split and quotes

2005-04-06 Thread C Smith
I wish it would leave the stuff in quotes in tact: If you first split on your delimiter (which must have a matching one) you will obtain a list in which every odd position contains a string that was quoted. Step through the result and split the ones that are not quoted ones but don't do anythin

RE: [Tutor] str.split and quotes

2005-04-06 Thread Marilyn Davis
On Wed, 6 Apr 2005, Tony Meyer wrote: > > >>> s = 'Hi "Python Tutors" please help' > > >>> s.split() > > ['Hi', '"Python', 'Tutors"', 'please', 'help'] > > >>> > > > > I wish it would leave the stuff in quotes in tact: > > > > ['Hi', '"Python Tutors"', 'please', 'help'] > > You can do this wit

Re: [Tutor] str.split and quotes

2005-04-06 Thread Kent Johnson
Marilyn Davis wrote: Hi Tutors, I need a little help with this, if anyone has the time and inclination: s = 'Hi "Python Tutors" please help' s.split() ['Hi', '"Python', 'Tutors"', 'please', 'help'] I wish it would leave the stuff in quotes in tact: ['Hi', '"Python Tutors"', 'please', 'help'] You c

RE: [Tutor] str.split and quotes

2005-04-06 Thread Tony Meyer
> That won't work for the general case. I spent about 30 minutes trying > to come up with a reliably non-re way and kept hitting bugs like the > one here. Given that Tony_combine is a function wrapping Tony's logic: > > >>> Tony_combine('This will not work as "more than two words" are > quoted

Re: [Tutor] str.split and quotes

2005-04-05 Thread Brian van den Broek
Tony Meyer said unto the world upon 2005-04-06 01:59: s = 'Hi "Python Tutors" please help' s.split() ['Hi', '"Python', 'Tutors"', 'please', 'help'] I wish it would leave the stuff in quotes in tact: ['Hi', '"Python Tutors"', 'please', 'help'] You can do this with a regular expression: Or you can

[Tutor] str.split and quotes

2005-04-05 Thread Marilyn Davis
Hi Tutors, I need a little help with this, if anyone has the time and inclination: >>> s = 'Hi "Python Tutors" please help' >>> s.split() ['Hi', '"Python', 'Tutors"', 'please', 'help'] >>> I wish it would leave the stuff in quotes in tact: ['Hi', '"Python Tutors"', 'please', 'help'] Any sugge

RE: [Tutor] str.split and quotes

2005-04-05 Thread Tony Meyer
> I recommend this http://www.amk.ca/python/howto/regex/ > and python2x/tools/scripts/redemo.py to learn how to use regexes well. I also highly recommend for learning how to use regexes. In addition, Kodos is a great tool to both experiment around with reg

Re: [Tutor] str.split and quotes

2005-04-05 Thread Liam Clarke
Hi Marilyn, Before you get numerous suggestions to use regexes (which was my first idea), you could use the split method to do it - >>> q = 'Hi "Python Tutors" please help' >>> w = q.split('\"') >>> print w ['Hi ', 'Python Tutors', ' please help'] I'm splitting using a double speech mark as t

RE: [Tutor] str.split and quotes

2005-04-05 Thread Tony Meyer
> >>> s = 'Hi "Python Tutors" please help' > >>> s.split() > ['Hi', '"Python', 'Tutors"', 'please', 'help'] > >>> > > I wish it would leave the stuff in quotes in tact: > > ['Hi', '"Python Tutors"', 'please', 'help'] You can do this with a regular expression: >>> import re >>> re.findall(r'\".