Re: [Tutor] regex question

2011-01-04 Thread Richard D. Moores
On Tue, Jan 4, 2011 at 14:58, Steven D'Aprano wrote: > Dave Angel wrote: > >> One hazard is if the string the user inputs has any regex special >> characters in it.  If it's anything but letters and digits you probably want >> to escape it before combining it with your \\b strings. > > It is best

Re: [Tutor] print stack traces not caused by errors

2011-01-04 Thread ALAN GAULD
> and I will figure out how to get more. I will definitely look at > setting breakpoints in the event handlers (every event is fired by a > keystroke controled in an accelerator table). It doesn't matter about the events, only the handler. Provided you know the handler function that gets cal

Re: [Tutor] print stack traces not caused by errors

2011-01-04 Thread Corey Richardson
On 01/04/2011 06:59 PM, Alan Gauld wrote: > > "Alex Hall" wrote > >> expected at all. I tried the pdb module, but I am running a wx >> program >> so it is not helping. I tried: >> python -m pdb c:\prog\solitaire\game.py > > The key to using any debugger in a GUI environment is to set break > p

Re: [Tutor] print stack traces not caused by errors

2011-01-04 Thread Alex Hall
Thanks to both of you. While I am not getting as much information from pdb as I get from an error traceback, I suspect that it is my fault and I will figure out how to get more. I will definitely look at setting breakpoints in the event handlers (every event is fired by a keystroke controled in an

Re: [Tutor] print stack traces not caused by errors

2011-01-04 Thread Alan Gauld
"Alex Hall" wrote expected at all. I tried the pdb module, but I am running a wx program so it is not helping. I tried: python -m pdb c:\prog\solitaire\game.py The key to using any debugger in a GUI environment is to set break points on the event handlers of interest. Then when the event fi

Re: [Tutor] regex question

2011-01-04 Thread Steven D'Aprano
Dave Angel wrote: One hazard is if the string the user inputs has any regex special characters in it. If it's anything but letters and digits you probably want to escape it before combining it with your \\b strings. It is best to escape any user-input before passing it to regex regardless.

Re: [Tutor] regex question

2011-01-04 Thread Dave Angel
On 01/-10/-28163 02:59 PM, Richard D. Moores wrote: On Tue, Jan 4, 2011 at 11:57, Richard D. Moores wrote: On Tue, Jan 4, 2011 at 10:41, Richard D. Moores wrote: Please see http://tutoree7.pastebin.com/z9YeSYRw . I'm actually searching RTF files, not TXT files. I want to modify this script t

Re: [Tutor] Beginning Python and other resources (was Re: SlicingTuples)

2011-01-04 Thread Patty
Hi David - I was looking for the book you recomended below - "Python 3 Object Oriented Programming" by Dusty Phillips - and found it on Amazon for $43 new on up and $70 for used but maybe that was hardback? Do you happen to know of some other way to obtain it for less than $45? Thanks Patty

Re: [Tutor] regex question

2011-01-04 Thread Richard D. Moores
On Tue, Jan 4, 2011 at 11:57, Richard D. Moores wrote: > On Tue, Jan 4, 2011 at 10:41, Richard D. Moores wrote: >> Please see http://tutoree7.pastebin.com/z9YeSYRw . I'm actually >> searching RTF files, not TXT files. >> >> I want to modify this script to handle searching on a word. So what, >> f

Re: [Tutor] regex question

2011-01-04 Thread Richard D. Moores
On Tue, Jan 4, 2011 at 10:41, Richard D. Moores wrote: > Please see http://tutoree7.pastebin.com/z9YeSYRw . I'm actually > searching RTF files, not TXT files. > > I want to modify this script to handle searching on a word. So what, > for example, should line 71 be? OK, I think I've got it. in pl

Re: [Tutor] regex question

2011-01-04 Thread Richard D. Moores
Please see http://tutoree7.pastebin.com/z9YeSYRw . I'm actually searching RTF files, not TXT files. I want to modify this script to handle searching on a word. So what, for example, should line 71 be? Dick ___ Tutor maillist - Tutor@python.org To unsu

Re: [Tutor] regex question

2011-01-04 Thread Brett Ritter
On Tue, Jan 4, 2011 at 11:07 AM, Richard D. Moores wrote: > A file has these 2 lines: > > alksdhjf ksjhdf kjshf dex akjdhf jkdshf jsdhf > alkdshf jkashd flkjdsf index alkdjshf alkdjshf > > And I want the only line that contains the word "dex" Ah! Then you want a slightly different Regex pattern.

Re: [Tutor] regex question

2011-01-04 Thread Richard D. Moores
On Tue, Jan 4, 2011 at 09:31, Brett Ritter wrote: > On Tue, Jan 4, 2011 at 10:37 AM, Richard D. Moores wrote: >> regex = ".*" + search + ".*" >> p = re.compile(regex, re.I) > > Just having "search" as your regex is fine (it will search for the > pattern _in_ the string, no need to specify the ot

Re: [Tutor] regex question

2011-01-04 Thread Brett Ritter
On Tue, Jan 4, 2011 at 10:37 AM, Richard D. Moores wrote: > regex = ".*" + search + ".*" > p = re.compile(regex, re.I) > > in finding lines in a text file that contain search, a string entered > at a prompt. That's an inefficient regex (though the compiler may be smart enough to prune the unneede

Re: [Tutor] print stack traces not caused by errors

2011-01-04 Thread Hugo Arts
On Tue, Jan 4, 2011 at 5:26 PM, Alex Hall wrote: > Hi all, > I am coming along quite nicely with Solitaire (sans graphics). > However, I am getting some odd behavior, and I would like to see what > is calling what so I can see where things are going wrong. It is not > causing an error to print a t

[Tutor] print stack traces not caused by errors

2011-01-04 Thread Alex Hall
Hi all, I am coming along quite nicely with Solitaire (sans graphics). However, I am getting some odd behavior, and I would like to see what is calling what so I can see where things are going wrong. It is not causing an error to print a traceback, but it is not doing what I expected at all. I trie

Re: [Tutor] regex question

2011-01-04 Thread Richard D. Moores
On Tue, Jan 4, 2011 at 07:55, Wayne Werner wrote: > On Tue, Jan 4, 2011 at 9:37 AM, Richard D. Moores > You could use (2.6+ I think): > word = raw_input('Enter word to search for: ') > with open('somefile.txt') as f: >    for line in f: >        if word in line: >             print line I think

Re: [Tutor] matplotlib.pylab.plotfile formatting help

2011-01-04 Thread Evert Rol
Hi Sean, > I've got a csv file that contains two data fields, the short name of a > month and an integer. I'm experimenting with pylab and ipython to get > a feel for how pylab works. I'm able to generate a bar graph from my > data, but there are two problems with it: > > 1. I don't want "20

Re: [Tutor] regex question

2011-01-04 Thread Wayne Werner
On Tue, Jan 4, 2011 at 9:37 AM, Richard D. Moores wrote: > I use > > regex = ".*" + search + ".*" > p = re.compile(regex, re.I) > > in finding lines in a text file that contain search, a string entered > at a prompt. > > What regex do I use to find lines in a text file that contain search, > where

[Tutor] regex question

2011-01-04 Thread Richard D. Moores
I use regex = ".*" + search + ".*" p = re.compile(regex, re.I) in finding lines in a text file that contain search, a string entered at a prompt. What regex do I use to find lines in a text file that contain search, where search is a word entered at a prompt? Thanks, Dick Moores __

Re: [Tutor] Initialize values from a text input file

2011-01-04 Thread Steven D'Aprano
Tim Johnson wrote: consider the following console session: L = ['foo','bar'] locals()[L[0]] = L[1] [...] (2) Even if it did work, do you trust the source of the text? Taking external data provided by arbitrary untrusted users and turning it into variables is a good way to have your compute