Re: Improving my text processing script

2005-09-01 Thread Paul McGuire
Yes indeed, the real data often has surprising differences from the simulations! :) It turns out that pyparsing LineStart()'s are pretty fussy. Usually, pyparsing is very forgiving about whitespace between expressions, but it turns out that LineStart *must* be followed by the next expression, wit

Re: Find day of week from month and year

2005-09-03 Thread Paul McGuire
Donn, You didn't look closely enough at those results. The OP's point was that he did not know how to set all the tuple values correctly. Here's a clearer example, I think: import time print time.asctime((2005,9,1,0,0,0,0,0,0)) print time.asctime((2005,9,1,0,0,0,1,0,0)) print time.asctime((2005

Re: Magic Optimisation

2005-09-04 Thread Paul McGuire
This isn't much prettier, but what if you extract the try-except overhead out from the while loop? You only expect the exception to fire one time, at the end of the list. You can also eliminate any localization of variables for calls that are not called in the loop, such as self_pool (which does

Re: Magic Optimisation

2005-09-05 Thread Paul McGuire
I still think there are savings to be had by looping inside the try-except block, which avoids many setup/teardown exception handling steps. This is not so pretty in another way (repeated while on check()), but I would be interested in your timings w.r.t. your current code. def loop(self):

Re: Magic Optimisation

2005-09-05 Thread Paul McGuire
Raymond Hettinger posted this recipe to the Python Cookbook. I've not tried it myself, but it sounds like what you're looking for. http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/277940 -- Paul -- http://mail.python.org/mailman/listinfo/python-list

Re: Generators and Decorators doing my head in ..

2005-09-06 Thread Paul McGuire
Compare this to your original: def logFunctionCalls(function): ec = FunctionCounter() def decoratedFunction(*args,**kwargs): print "Entering function:", function.__name__, ec.next() function(*args,**kwargs) return decoratedFunction @logFunctionCalls def doWork(): p

Re: make sure entire string was parsed

2005-09-10 Thread Paul McGuire
Steven - Thanks for giving pyparsing a try! To see whether your input text consumes the whole string, add a StringEnd() element to the end of your BNF. Then if there is more text after the parsed text, parseString will throw a ParseException. I notice you call leaveWhitespace on several of your

Re: make sure entire string was parsed

2005-09-11 Thread Paul McGuire
Steve - >>I have to differentiate between: >> (NP -x-y) >>and: >> (NP-x -y) >>I'm doing this now using Combine. Does that seem right? If your word char set is just alphanums+"-", then this will work without doing anything unnatural with leaveWhitespace: from pyparsing import * thing = Word

Re: make sure entire string was parsed

2005-09-12 Thread Paul McGuire
Steve - Wow, this is a pretty dense pyparsing program. You are really pushing the envelope in your use of ParseResults, dicts, etc., but pretty much everything seems to be working. I still don't know the BNF you are working from, but here are some other "shots in the dark": 1. I'm surprised fun

ANN: pyparsing-1.3.3 released

2005-09-13 Thread Paul McGuire
Pyparsing 1.3.3 contains mostly bugfixes and minor enhancements over previous releases, including some improvement in Unicode support. Here are the change notes: Version 1.3.3 - September 12, 2005 -- - Improved support for Unicode strings that would be returned usi

Re: Magic Optimisation

2005-09-14 Thread Paul McGuire
Terry - If setting up a try-block is as fast (or "takes as long") as one iteration loop, then wont putting a try-block inside a loop double the execution time? -- Paul -- http://mail.python.org/mailman/listinfo/python-list

Re: Writing at the beginning of a file

2005-09-14 Thread Paul McGuire
Thierry - Check out the StringIO module. It will allow you to buffer the whole file into a string, and then give you a pseudo file pointer to the string buffer, so that your "fp.write"s will work unchanged. -- Paul -- http://mail.python.org/mailman/listinfo/python-list

Frivolous pursuit - automated game playing program

2005-09-14 Thread Paul McGuire
My son showed me this Flash game, Orbit (there are *many* links on the web out there for it, here's one for the Google-challenged: http://uploads.ungrounded.net/25/250408_orbit.swf), and it is *addicting*. Basically, you control a comet to traverse through the gravitational fields of randomly

Re: Looking for a database. Sugestions?

2005-09-15 Thread Paul McGuire
SQLite is very easy to get started with. I loaded up a 9 Mb file of process data and the performance was pretty good after I indexed on the join columns (increased db file size to 15Mb). Supports transactions, cursors, typed data. I *think* it is thread-safe, but I'm not positive. But it's grea

Re: How to program efficient pattern searches in a list of float numbers?

2005-09-19 Thread Paul McGuire
Have you tried coding even the brute-force naive search? It is far easier to improve an algorithm when you have someplace relatively concrete to start from. Plus, the naive approach is most likely to return a correct result, so that you can regression test your exotic interval-skipping, second-de

Re: Object default value

2005-09-20 Thread Paul McGuire
> I think you want to overload the assignment operator here. I'm not sure that > is allowed in python (I've never seen it done). You can't because assignment is not an operator in Python. Is it safe to assume that the OP's next question will be how to invoke functions without the ()'s? To save y

Re: Line Scan and Removal

2005-09-20 Thread Paul McGuire
"PyPK" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > i I need some help on some problem I am trying to think of. > > are there any algorithms available to do the following If not, any > ideas?: > > I would like to Identify any lines of any orientation and width in an > Image and > r

Re: Writing a parser the right way?

2005-09-21 Thread Paul McGuire
"beza1e1" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > I'm writing a parser for english language. This is a simple function to > identify, what kind of sentence we have. Do you think, this class > wrapping is right to represent the result of the function? Further > parsing then che

Re: which parser to use

2005-02-23 Thread Paul McGuire
[EMAIL PROTECTED] wrote: > I'm building something that requires parsing a rather complex > language. I'd like to do the whole application, including the > lex/parse phase, in Python (for development/debug speed), and only > move parts of it to a compiled language if execution speed absolutely > dic

Re: [perl-python] exercise: partition a list by equivalence

2005-02-23 Thread Paul McGuire
Please consider my submission also (Python 2.3-compatible). -- Paul McGuire .import sets . .input = [[1, 2], [3, 4], [2, 3], [4, 5]] .input = [[1, 2], [3, 4], [4, 5]] .input = [[1, 2],[2,1], [3, 4], [4, 5],[2,2],[2,3],[6,6]] . .def merge(pairings): .ret

Re: [perl-python] exercise: partition a list by equivalence

2005-02-24 Thread Paul McGuire
A slightly better version, only walks the set of cumulative list of sets once per pairing. -- Paul .import sets . .input = [[1, 2], [3, 4], [2, 3], [4, 5]] .input = [[1, 2], [3, 4], [4, 5]] .input = [[1, 2],[2,1], [3, 4], [4, 5],[2,2],[2,3],[6,6]] . .def merge(pairings): .ret

Re: parse lines to name value pairs

2005-02-27 Thread Paul McGuire
Gee, no takers? Here's a (surprise!) pyparsing solution. -- Paul .# get pyparsing at http://pyparsing.sourceforge.net . .from pyparsing import quotedString, printables, Word, OneOrMore, Forward, Literal,delimitedList,Group .quotedString.setParseAction(lambda s,l,t: t[0].strip("'\"")) . .line1 =

Re: parse lines to name value pairs

2005-02-27 Thread Paul McGuire
Damned cut-and-paste in GoogleGroups edit window (leading '.'s are to retain spacing): .# get pyparsing at http://pyparsing.sourceforge.net . .from pyparsing import quotedString, printables, Word, OneOrMore, Forward, Literal,delimitedList,Group . .line1 = """path {{data/tom} C:/user/john}""" .line

Re: greedy match wanted

2005-03-03 Thread Paul McGuire
This is very similar to some common problems in developing pyparsing grammars. One of my early attempts at parsing CORBA IDL listed the valid parameter passing mechanisms as ('in' | 'out' | 'inout'). As you can imagine, I never successfully matched an 'inout', since the 'in' match came first. (P

Re: GOTO (was Re: Appeal for python developers)

2005-03-05 Thread Paul McGuire
At the risk of beating this into the Pythonic ground, here is a generator version which collapses the original nested loop into a single loop, so that break works just fine: .def getCombinations(*args): .if len(args) > 1: .for a0 in args[0]: .for remainder in ge

Re: split a string with quoted parts into list

2005-03-10 Thread Paul McGuire
Oliver - Here is a simpler approach, hopefully more readable, using pyparsing (at http://pyparsing.sourceforge.net). I also added another test word to your sample input line, one consisting of a lone pair of double quotes, signifying an empty string. (Be sure to remove leading '.'s from Python t

Re: Turning String into Numerical Equation

2005-03-13 Thread Paul McGuire
Almost this exact parser, called fourFn.py, is included in the examples with pyparsing (at http://pyparsing.sourceforge.net). Since it is pure Python, you can extend the grammar with whatever builtin functions you like. But it *is* a parser, not just a short cut. -- Paul -- http://mail.python.

Re: Splitting with Regular Expressions

2005-03-17 Thread Paul McGuire
A pyparsing example may be less mysterious. You can define words to be any group of alphas, or you can define a word to be alphas concatenated by '.'s. scanString is a generator that scans for matches in the input string and returns the matching token list, and the start and end location of the m

Re: how to handle repetitive regexp match checks

2005-03-18 Thread Paul McGuire
Matt - Pyparsing may be of interest to you. One of its core features is the ability to associate an action method with a parsing pattern. During parsing, the action is called with the original source string, the location within the string of the match, and the matched tokens. Your code would lo

Re: Pre-PEP: Dictionary accumulator methods

2005-03-19 Thread Paul McGuire
-1 on set increment. I think this makes your intent much clearer: .d={} .for word in text.split(): .d.tally(word) .if word.lower() in ["a","an","the"]: .d.tally(word,-1) or perhaps simplest: .d={} .for word in text.split(): .if word.lower() not in ["a","an","the"]: .d

Re: decorators ?

2004-11-30 Thread Paul McGuire
"km" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Hi all, > was going thru the new features introduced into python2.4 version. > i was stuck with 'decorators' - can someone explain me the need of such a thing called decorators ? > tia > KM Here are some example on the Python Wik

Re: Mean, median, and mode

2004-12-06 Thread Paul McGuire
This median expression is incorrect. median is *not* the midpoint between max and min values. It is the middle value when all values are sorted (for an odd number of values), or the average of the two middle values when all values are sorted (for an even number of values). In Python 2.4 (needed

Re: Mean, median, and mode

2004-12-06 Thread Paul McGuire
"Paul McGuire" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > This median expression is incorrect. median is *not* the midpoint between > max and min values. It is the middle value when all values are sorted (for > an odd number of values), or the average

Re: Mean, median, and mode - third time's the charm!!!

2004-12-06 Thread Paul McGuire
"Paul McGuire" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > > "Paul McGuire" <[EMAIL PROTECTED]> wrote in message > news:[EMAIL PROTECTED] > > This median expression is incorrect. median is *not* the midpoint between > > max an

Re: cut strings and parse for images

2004-12-06 Thread Paul McGuire
"Andreas Volz" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Hi, > > I used SGMLParser to parse all href's in a html file. Now I need to cut > some strings. For example: > > http://www.example.com/dir/example.html > > Now I like to cut the string, so that only domain and directory i

Re: cut strings and parse for images

2004-12-06 Thread Paul McGuire
"Andreas Volz" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Am Mon, 06 Dec 2004 20:36:36 GMT schrieb Paul McGuire: > > > Check out the urlparse module (in std distribution). For images, you > > can provide a default addressing scheme, so you

Re: regex for url paramter

2004-12-07 Thread Paul McGuire
"Robert Brewer" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] Andreas Volz wrote: > I try to extract a http target from a URL that is given as parameter. > urlparse couldn't really help me. I tried it like this > > url="http://www.example.com/example.html?url=http://www.exampl > e.org

Re: Python for Palm OS?

2004-12-07 Thread Paul McGuire
"Maurice LING" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Or has anyone envisioned anything? > > Cheers > Maurice I just envisioned myself sipping a Mai Tai on a white sand beach, the surf gently murmuring in my ears, while getting a backrub from Carmen Electra. -- Paul --

Re: results of division

2004-12-09 Thread Paul McGuire
"Paul Rubin" wrote in message news:[EMAIL PROTECTED] > Brad Tilley <[EMAIL PROTECTED]> writes: > > What is the proper way to limit the results of division to only a few > > spaces after the decimal? I don't need rocket-science like > > precision. Here's an example: > > >

Re: lies about OOP

2004-12-14 Thread Paul McGuire
"Steve Holden" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Paul McGuire wrote: > > > "Jive" <[EMAIL PROTECTED]> wrote in message > > news:[EMAIL PROTECTED] > > > > > > > >>But by '86, the Joy

Re: pyparsing and 'keywords'

2004-12-14 Thread Paul McGuire
"Berteun Damman" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Hello, > > I'm having some problems with pyparsing, I could not find how to tell > it to view certain words as keywords, i.e. not as a possible variable > name (in an elegant way), > for example, I have this little gramm

Re: lies about OOP

2004-12-14 Thread Paul McGuire
"Roy Smith" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > I think the real reason Python is a better teaching language for > teaching OO concepts is because it just gives you the real core of OO: > inheritence, encapsulation, and association of functions with the data > they act on.

Re: gather information from various files efficiently

2004-12-15 Thread Paul McGuire
"Klaus Neuner" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Hello, > > I need to gather information that is contained in various files. > > Like so: > > file1: > = > foo : 1 2 > bar : 2 4 > baz : 3 > = > > file2: > = > foo

Re: lies about OOP

2004-12-14 Thread Paul McGuire
"Jive" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > > But by '86, the Joy of OOP was widely known. > "Widely known"? Errr? In 1986, "object-oriented" programming was barely marketing-speak. Computing hardware in the mid-80's just wasn't up to the task of dealing with OO memory

Re: pyparsing and 'keywords'

2004-12-14 Thread Paul McGuire
"Berteun Damman" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > On Tue, 14 Dec 2004 18:39:19 GMT, Paul McGuire > <[EMAIL PROTECTED]> wrote: > >> If I try however to parse the String "if test; testagain; fi;", it does > >> no

Re: lies about OOP

2004-12-14 Thread Paul McGuire
"Martijn Faassen" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Paul McGuire wrote: > [snip] > > I would characterize the 80's as the transitional decade from structured > > programming (which really started to hit its stride when Djikstr

Re: flex/bison like module in Python?

2004-12-15 Thread Paul McGuire
"Jerry Sievers" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Dear Pythonists; > > Curious if there exists in Python package(s) for use as lexer/parser > for implementation of language grammars? > > Already using cmd.py from the standard distro for it's basic features > but wishing

Re: I DECLARE THIS THREAD FINISHED

2004-12-15 Thread Paul McGuire
"Jive" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Everyone keep moving. There is nothing to see here. Move along. > You wish! If only ending a thread were that easy - we wouldn't be hearing about "Why is Python slower than Java?" anymore! But I agree with Martijn (note spell

Re: Code without effect (wx demo TreeCtrl.py ImageList)

2004-12-20 Thread Paul McGuire
"Martin Drautzburg" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > In the wx demoy TreeCtrl.py I find the following code, that should > have no effect but seems to be needed nevertheless. > > class TestTreeCtrlPanel(wx.Panel): > def __init__(self, parent, log): > [...} >

Re: mathmatical expressions evaluation

2004-12-22 Thread Paul McGuire
"Tonino" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Hi, > > I have a task of evaluating a complex series (sorta) of mathematical > expressions and getting an answer ... > > I have looked at the numarray (not really suited??) and pythonica (too > simple??) and even tried using eva

Re: Pyparsing: Non-greedy matching?

2004-12-30 Thread Paul McGuire
"Peter Fein" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > I'm trying to use pyparsing write a screenscraper. I've got some > arbitrary HTML text I define as opener & closer. In between is the HTML > data I want to extract. However, the data may contain the same > characters as u

Re: Overloaded Constructors?!?

2005-03-20 Thread Paul McGuire
>>Another way is to make two factory methods that >>create instances of the class and do the correct initialization. >I am sorry to be so tedious, but I am still quite a >newbie in Python... could you please provide a very >small example of your last sentence? Looks >quite interesting... See the

Re: Text-to-speech

2005-03-21 Thread Paul McGuire
How about a clerihew instead of a limerick? Guido van Rossum Had an idea most awesome. When he lost track of his braces, Just replaced them with spaces. -- Paul McGuire -- http://mail.python.org/mailman/listinfo/python-list

Re: Text-to-speech

2005-03-21 Thread Paul McGuire
Brian, Having reviewed your Cease and Desist petition, I'm afraid I must dispute some or all of your claims: 1. Your citation of prior art has one or more significant defects: a. In your citation, "brace" is clearly rhymed with "whitespace", not "space". The broad concept of "whitespace" is subs

Re: An Abridged Python Tutorial

2005-03-24 Thread Paul McGuire
This will be tough to beat! (and not a single rhyme of "brace" and "space"!) -- Paul -- http://mail.python.org/mailman/listinfo/python-list

Re: Grouping code by indentation - feature or ******?

2005-03-25 Thread Paul McGuire
My favorite part is not getting into religious coder wars over where the (@#$&(&!!$ braces go! Let the indentation (which you do anyway, even when you have braces) do the grouping. -- Paul BTW - anyone who tries to justify code design based on "eliminating keypresses," or, my God!, "saving space

ANN: pyparsing-1.3 released

2005-03-26 Thread Paul McGuire
fined debugging actions. - Added support for escaped quotes (either in \', \", or doubled quote form) to the predefined expressions for quoted strings. (Thanks, Ero Carrera!) - Minor performance improvement (~5%) converting "char in string" tests to "char in dict". (S

Re: regular expression

2005-03-26 Thread Paul McGuire
Aaron - Here's a pyparsing approach (requires latest 1.3 pyparsing version). It may not be as terse or fast as your regexp, but it may be easier to maintain. By defining floatNum ahead of DOT in the scanner definition, you specify the dot-containing expressions that you do *not* want to have dots

Re: String Splitter Brain Teaser

2005-03-27 Thread Paul McGuire
Using a parser may sound like overkill, but why not when it's this easy? Get the latest pyparsing at http://pyparsing.sourceforge.net. -- Paul from pyparsing import oneOf, Group, OneOrMore, Literal testdata = "ATT/GATA/G" marker = oneOf( "A T G C") SLASH = Literal("/").suppress() genDegenList

Re: PyParsing module or HTMLParser

2005-03-29 Thread Paul McGuire
La - In general, I have shied away from doing general-purpose HTML parsing with pyparsing. It's a crowded field, and it's likely that there are better candidates out there for your problem. I've heard good things about BeautifulSoup, but I've also heard from at least one person that they prefer

Re: how do you use a closure in a class

2005-03-29 Thread Paul McGuire
Well, I'm not sure "closure" is the Pythonic way. But in Python, you can use functions to dynamically create other functions. Here's an example of this feature (although there are far simpler ways to do this), tallying vowels and consonants in an input string by calling a function looked up in a

Re: how do you use a closure in a class

2005-03-29 Thread Paul McGuire
Well, despite my parenthetical disclaimer, my attempted point was that the OP wanted to avoid replicating several functions that were mostly the same. I think Python's idiom of using a function to create and return callables is a comparable feature to using anonymous closures. Unfortunately, I gue

Re: Things you shouldn't do

2005-03-29 Thread Paul McGuire
This struck me also when I first saw this post. It reminded me of a body of code I inherited at a former job, that I had to help untangle. The code was filled with two key variables: t_1 and t_l. Printing out the source in a Courier font made these two vars completely indistinguishable, and it to

Re: how do you use a closure in a class

2005-03-30 Thread Paul McGuire
See the following. -- Paul class X(object): pass def makeAddr(tAdd): def add(self, tNum): return tNum + tAdd return add # add methods to class X X.add1 = makeAddr(1) X.add100 = makeAddr(100) # create an X object x = X() # invoke new methods print x.add1( 50 ) print x.add100

Re: Things you shouldn't do

2005-03-30 Thread Paul McGuire
Here's another real world example, although it was in C: char* ptr; assert( ptr = malloc( memsize ); ) Of course, this worked when built in debug, but it took a while to track down why it wasn't working in the release build (the assert()'s were stripped out in the release builds, so ptr didn't al

Re: PyParsing module or HTMLParser

2005-03-30 Thread Paul McGuire
Lad - Well, here's what I've got so far. I'll leave the extraction of the description to you as an exercise, but as a clue, it looks like it is delimited by "View Detail " at the beginning, and "Quantity: 500" at the end, where 500 could be any number. This program will print out: ['Title:', 'S

Re: PyParsing module or HTMLParser

2005-03-31 Thread Paul McGuire
Yes, drop me a note if you get stuck. -- Paul base64.decodestring('cHRtY2dAYXVzdGluLnJyLmNvbQ==') -- http://mail.python.org/mailman/listinfo/python-list

Re: Best editor?

2005-04-05 Thread Paul McGuire
SciTE (Scintilla Text Editor) is just right for me too. Low overhead, great just as a Notepad alternative, but with good coding support too. -- Paul -- http://mail.python.org/mailman/listinfo/python-list

Re: text processing problem

2005-04-07 Thread Paul McGuire
Maurice - Here is a pyparsing treatment of your problem. It is certainly more verbose, but hopefully easier to follow and later maintain (modifying valid word characters, for instance). pyparsing implicitly ignores whitespace, so tabs and newlines within the expression are easily skipped, withou

Re: XML parsing per record

2005-04-21 Thread Paul McGuire
Don't assume that just because you have a 2.4G XML file that you have 2.4G of data. Looking at these verbose tags, plus the fact that the XML is pretty-printed (all those leading spaces - not even tabs! - add up), I'm guessing you only have about 5-10% actual data, and the rest is just XML tagging

Re: recording data between [ and ]

2005-04-21 Thread Paul McGuire
Jay - Thanks for the pyparsing plug. Here is how the OP's program would look using pyparsing: import pyparsing fp = file('filename') data = fp.read() fp.close() foo = '''stuff [lsass.exe] [System] more stuff x [firefox.exe] .. ''' LBRACK = pyparsing.Literal("[").suppress() RBRACK

Re: Regular Expressions - Python vs Perl

2005-04-21 Thread Paul McGuire
I'd be very interested to see if there actually is a benchmark suite for regexp's. I imagine that this could be an easy area for quite a varied set of results, depending on the expression features included in the actual regexp being tested, and even the nature of the input text. For example, a sim

Re: Order of elements in a dict

2005-04-26 Thread Paul McGuire
Here is a brute-force list comprehension that does not depend on preserving order between dict.keys() and dict.values(): dict( [ (a[1],a[0]) for a in d.items() ] ) Or for map/lambda lovers: rev = lambda a: (a[1],a[0]) dict( map( rev, d.items() ) But you still have no control over the order retu

Re: Quote-aware string splitting

2005-04-26 Thread Paul McGuire
Quoted strings are surprisingly stateful, so that using a parser isn't totally out of line. Here is a pyparsing example with some added test cases. Pyparsing's quotedString built-in handles single or double quotes (if you don't want to be this permissive, there are also sglQuotedString and dblQuo

Re: How do I parse this ? regexp ?

2005-04-27 Thread Paul McGuire
Jake - If regexp's give you pause, here is a pyparsing version that, while verbose, is fairly straightforward. I made some guesses at what some of the data fields might be, but that doesn't matter much. Note the use of setResultsName() to give different parse fragments names so that they are dir

Who is using littletable?

2015-08-17 Thread Paul McGuire
littletable is a little module I knocked together a few years ago, found it sort of useful, so uploaded to SF and PyPI. The download traffic at SF is very light, as I expected, but PyPI shows > 3000 downloads in the past month! Who *are* all these people? In my own continuing self-education,

Re: python command not working

2015-08-17 Thread Paul McGuire
On Friday, August 14, 2015 at 6:13:37 AM UTC-5, sam.h...@gmail.com wrote: > On Wednesday, April 22, 2009 at 8:36:21 AM UTC+1, David Cournapeau wrote: > > On Wed, Apr 22, 2009 at 4:20 PM, 83nini <83n...@gmail.com> wrote: > > > Hi guys, > > > > > > I'm new to python, i downloaded version 2.5, opened

Re: Python re to extract useful information from each line

2015-08-19 Thread Paul McGuire
Here is a first shot at a pyparsing parser for these lines: from pyparsing import * SET,POLICY,ID,FROM,TO,NAT,SRC,DST,IP,PORT,SCHEDULE,LOG,PERMIT,ALLOW,DENY = map(CaselessKeyword, "SET,POLICY,ID,FROM,TO,NAT,SRC,DST,IP,PORT,SCHEDULE,LOG,PERMIT,ALLOW,DENY".split(',')) integer = Word(nums) ipA

Re: First practical Python code, comments appreciated

2005-12-14 Thread Paul McGuire
"Steve Holden" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > That form is non-portable. You might argue "I'm never going to run this > program on anything other than Windows", and indeed for throwaway > programs it's often easier to write something non-portable. It's > surprising, t

Re: Newbie needs help with regex strings

2005-12-14 Thread Paul McGuire
This isn't a regex solution, but uses pyparsing instead. Pyparsing helps you construct recursive-descent parsers, and maintains a code structure that is easy to compose, read, understand, maintain, and remember what you did 6-months after you wrote it in the first place. Download pyparsing at htt

Re: split string saving screened spaces

2005-12-16 Thread Paul McGuire
Pyparsing has built-in quoted string support. from pyparsing import OneOrMore,Word,alphanums,quotedString item = Word('-',alphanums) | quotedString | Word(alphanums) items = OneOrMore(item) print items.parseString( "-a -b -c '1 2 3' -d 5 -e zork2000" ) gives: ['-a', '-b', '-c', "'1 2 3'", '-d'

Re: Parser or regex ?

2005-12-16 Thread Paul McGuire
"Fuzzyman" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > > Tim Arnold wrote: > > "Fuzzyman" <[EMAIL PROTECTED]> wrote in message > > news:[EMAIL PROTECTED] > > > Hello all, > > > > > > I'm writing a module that takes user input as strings and (effectively) > > > translates them to f

Re: Trying to find regex for any script in an html source

2005-12-21 Thread Paul McGuire
"28tommy" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Hi, > I'm trying to find scripts in html source of a page retrieved from the > web. > I'm trying to use the following rule: > > match = re.compile('') > > 28tommy - pyparsing includes a built-in HTML tag definitio

Re: Indentation/whitespace

2005-12-25 Thread Paul McGuire
"Lee Harr" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > On 2005-12-23, Gary Herron <[EMAIL PROTECTED]> wrote: > > You've got the visible/invisible aspect of things > > *exactly* backwards. > > The point on a line of text where things change > > from white space to > > non-white spa

Re: python coding contest

2005-12-27 Thread Paul McGuire
"Scott David Daniels" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Remi Villatel wrote: > > Tim Hochberg wrote: > > > >>> I am currently at 39 bytes following the requirements and the > >>> principle given above (my module passes the test). Anyone able to > >>> beat that? > > > >>

Re: python coding contest

2005-12-27 Thread Paul McGuire
"Paul McGuire" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Well *I'm* certainly looking forward to learning some new tricks! My > (non-cheat) version is a comparatively-portly 245, and no alternatives are > popping into my head at the moment! &

Re: python coding contest

2005-12-27 Thread Paul McGuire
"Shane Hathaway" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > > I'm down to 133 characters (counted according to 'wc -c') on a single > line. It contains about 11 whitespace characters (depending on what you > consider whitespace.) It's way too tricky for my taste, but it's fun t

Re: Newbie needs help extracting data from XML

2005-12-28 Thread Paul McGuire
"Rodney" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Hi, > > Im a Python newbie and am trying to get the data out of a series of XML > files. So for example the xml is: > > xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"; > xmlns:soapenc="http://schemas.xmlsoap.org/soap/e

Re: Graphviz/dot language formatter

2005-12-29 Thread Paul McGuire
[EMAIL PROTECTED] wrote: > Hi, > I am new to Graphviz/dot language, the source .dot files are chaos so I > am looking for source formatter for the .dot files, any ideas? Pydot is a pyparsing-based parser at http://dkbza.org/pydot.html. This may give you a jump on source formatting. -- Paul --

Re: Modifying values in a list

2005-12-29 Thread Paul McGuire
As others have already posted, changing the value of 'value' has nothing to do with the list variable 'numbers'. To modify the list in place, you need to access its members by index. The following code does this: numbers = [1,2,3] for i in range(len(numbers)): numbers[i] *= 2 print numbers

Re: Distributions, RE-verb and the like

2005-12-29 Thread Paul McGuire
Bearophile - Well, I fear this may end up being another of those "easier to reinvent" wheels. All of your issues with RE's are the same ones I had with lex/yacc (and re's too) when I wrote pyparsing. Any chance for convergence here? (BTW, there is nothing inherently wrong with "reinventing whee

Re: Distributions, RE-verb and the like

2005-12-29 Thread Paul McGuire
Oh, the pyparsing rendition of your initial pat expression would be something like: import pyparsing as pp pat = pp.Combine( pp.oneOf("$ 0x 0X") + pp.Word(pp.hexnums,max=8) ) Combine is needed to ensure that the leading $, 0x, or 0X is immediately followed by 1-8 (and no more than 8) hex digits.

Re: Array construction from object members

2005-12-31 Thread Paul McGuire
"MKoool" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Hi everyone, > > I am doing several operations on lists and I am wondering if python has > anything built in to get every member of several objects that are in an > array, <-snip-> > Here's some sample code to show you how list

Re: trouble pyparsing

2006-01-04 Thread Paul McGuire
"the.theorist" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Hey, I'm trying my hand and pyparsing a log file (named l.log): > FIRSTLINE > > PROPERTY1 DATA1 > PROPERTY2 DATA2 > > PROPERTYS LIST > ID1 data1 > ID2 data2 > > ID1 data11 >

Re: Regex help needed

2006-01-10 Thread Paul McGuire
"rh0dium" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Hi all, > > I am using python to drive another tool using pexpect. The values > which I get back I would like to automatically put into a list if there > is more than one return value. They provide me a way to see that the > d

Re: Regex help needed

2006-01-10 Thread Paul McGuire
"rh0dium" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > > Paul McGuire wrote: > > -- Paul > > (Download pyparsing at http://pyparsing.sourceforge.net.) > > Done. > > > Hey this is pretty cool! I have one small problem that I don

Re: Regex help needed

2006-01-10 Thread Paul McGuire
"rh0dium" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > > Paul McGuire wrote: > > > ident = Combine( Word(alpha,alphanums+"_") + LPAR + RPAR ) > > This will only work for a word with a parentheses ( ie. somefunction() > ) > >

Re: Can dictionaries be nested?

2006-01-12 Thread Paul McGuire
<[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > I'm parsing some data of the form: > > OuterName1 InnerName1=5,InnerName2=7,InnerName3=34; > OuterName2 InnerNameX=43,InnerNameY=67,InnerName3=21; > OuterName3 > and so on > I wrote pyparsing for just this kind of job. Using

Re: Parsing files -- pyparsing to the rescue?

2006-01-16 Thread Paul McGuire
"rh0dium" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Hi all, > > I have a file which I need to parse and I need to be able to break it > down by sections. I know it's possible but I can't seem to figure this > out. > > The sections are broken by <> with one or more keywords

Re: Shrinky-dink Python (also, non-Unicode Python build is broken)

2006-01-16 Thread Paul McGuire
"Larry Hastings" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Second of all, the dumb-as-a-bag-of-rocks Windows linker (at least > the one used by VC++ under MSVS .Net 2003) *links in unused static > symbols*. If I want to excise the code for a module, it is not > sufficient to co

<    1   2   3   4   5   6   7   8   9   10   >