[ANN] pyparsing 2.0.1 released - compatible with Python 2.6 and later

2013-07-20 Thread Paul McGuire
pport and interest in pyparsing! -- Paul McGuire -- http://mail.python.org/mailman/listinfo/python-list

Re: Problem installing Pyparsing

2013-07-20 Thread Paul McGuire
Pyparsing 2.0.1 fixes this incompatibility, and should work with all versions of Python 2.6 and later. -- Paul -- http://mail.python.org/mailman/listinfo/python-list

ANNOUNCE: pyparsing 1.5.7/2.0.0

2012-12-16 Thread Paul McGuire
With the release of version 2.0.0/1.5.7, pyparsing has now officially switched to Python 3.x support as its default installation environment. Python 2.x users can install the latest 1.5.7 release. (If you're using easy_install, do "easy_install pyparsing==1.5.7".) I'm taking this opportunity to

ANN: pyparsing 1.5.6 released!

2011-06-30 Thread Paul McGuire
After about 10 months, there is a new release of pyparsing, version 1.5.6. This release contains some small enhancements, some bugfixes, and some new examples. Most notably, this release includes the first public release of the Verilog parser. I have tired of restricting this parser for commerci

Re: Newbie regular expression and whitespace question

2005-09-22 Thread Paul McGuire
"googleboy" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Hi. > > I am trying to collapse an html table into a single line. Basically, > anytime I see ">" & "<" with nothing but whitespace between them, I'd > like to remove all the whitespace, including newlines. I've read the > h

Re: Newbie regular expression and whitespace question

2005-09-22 Thread Paul McGuire
"Fredrik Lundh" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > > > timeit -s "import test" "test.test3()" > 100 loops, best of 3: 6.73 msec per loop > > > timeit -s "import test" "test.test4()" > 1 loops, best of 3: 27.8 usec per loop > > that's a 240x slowdown. hmm. > > > > W

Re: Config parser module

2005-09-24 Thread Paul McGuire
<[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Hi all > I am a newbie and I just saw a ongoing thread on Fileprocessing which > talks abt config parser. > I have writen many pyhton program to parse many kind of text files by > using string module and regex. But after reading that con

Re: calling matlab

2005-10-12 Thread Paul McGuire
"Mohammed Smadi" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Hi; > > Does anyone know if we can call matlab for a python or bash script while > feeding the matlab script some command line arguments? I have an > interactive matlab script which i want to automate by feeding the arg

Re: replace words

2005-10-26 Thread Paul McGuire
[EMAIL PROTECTED] wrote: > What is the way for replacing in a string from . to . the sentence? > for example: > "been .taken. it may be .left. there, > even if the .live coals were not. cleared" > I want to do this-> replace(\.(.*)\.,\.start (1) end\.) > result: > "been .start taken end. it may

Re: Raw string fu

2005-10-26 Thread Paul McGuire
"Raw string fu"? A new martial art? -- http://mail.python.org/mailman/listinfo/python-list

Re: Quick way to test if value lies within a list of lists of ranges?

2005-10-27 Thread Paul McGuire
"Ben O'Steen" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] Scenario: = Using PyGame in particular, I am trying to write an application that will run a scripted timeline of events, eg at 5.5 seconds, play xxx.mp3 and put the image of a ball on screen, at 7.8 seconds move the

Re: need start point for getting html info from web

2005-10-30 Thread Paul McGuire
<[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > hey there, > > i have a small app that i am going to need to get information from a > few tables on different websites. i have looked at urllib and httplib. > the sites i need to get data from mostly have this data in tables. So > that,

Re: Getting a function name from string

2005-11-02 Thread Paul McGuire
"David Rasmussen" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > If I have a string that contains the name of a function, can I call it? > As in: > > def someFunction(): > print "Hello" > > s = "someFunction" > s() # I know this is wrong, but you get the idea... > > /David Lookup th

Re: how to present Python's OO feature in design?

2005-11-07 Thread Paul McGuire
They have a very good UML tool that has a Python plugin. I'd recommend the Professional Edition - the code reverse-engineering is like magic. Not open source or free, though. EA Pro is US$199, Academic license is US$105. But compare to Rational at $US000's, it is a great value f

Re: need help extracting data from a text file

2005-11-07 Thread Paul McGuire
<[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Hey there, > i have a text file with a bunch of values scattered throughout it. > i am needing to pull out a value that is in parenthesis right after a > certain word, > like the first time the word 'foo' is found, retrieve the values in

Re: [OT] Map of email origins to Python list

2005-11-07 Thread Paul McGuire
"Claire McLister" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] We've been working with Google Maps, and have created a web service to map origins of emails to a group. As a trial, we've developed a map of emails to this group at: http://www.zeesource.net/maps/map.do?group=668

Re: Any help with PLY?

2005-11-17 Thread Paul McGuire
<[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Hi folks, > > I've been trying to write a PLY parser and have run into a bit of > bother. > > At the moment, I have a RESERVEDWORD token which matches all reserved > words and then alters the token type to match the reserved word that >

Re: Hot to split string literals that will across two or more lines ?

2005-11-21 Thread Paul McGuire
"Ben Finney" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Xiao Jianfeng <[EMAIL PROTECTED]> wrote: > > I need to print a long sting, which is two long so it must expand > > two lines. > > How is this string being constructed in the source? If it exists as a > single long string, wh

Re: [pyparsing] How to get arbitrary text surrounded by keywords?

2005-11-28 Thread Paul McGuire
"Inyeol Lee" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > I'm trying to extract module contents from Verilog, which has the form > of; > > module foo (port1, port2, ... ); > > // module contents to extract here. > ... > > endmodule > > To extract the module

Re: aligning a set of word substrings to sentence

2005-12-01 Thread Paul McGuire
"Steven Bethard" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > I've got a list of word substrings (the "tokens") which I need to align > to a string of text (the "sentence"). The sentence is basically the > concatenation of the token list, with spaces sometimes inserted beetween >

Re: pyparsing with nested table

2005-12-08 Thread Paul McGuire
astarocean wrote: > using pyparsing to deal with nested tables , wanna keep table's > structure and propertys . > but program was chunked with the tag of inner table. > > have any ideas? > > here's the program > > > from pyparsing import * <... snip ...> > > tablePattern = Forward() <... sn

Re: pyparsing: how to negate a grammar

2005-01-09 Thread Paul McGuire
<[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Hi, > > I want to define a rule for a line that does NOT start with a given > Literal. How do I do that? I try the following and my program just hang > there: > > BodyLine = ~Literal("HTTP/1.1") + restOfLine > > Thanks, > Khoa > Khoa -

Re: pyparsing: how to negate a grammar

2005-01-09 Thread Paul McGuire
<[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Hi Paul, > > I am trying to extract HTTP response codes from a HTTP page send from > a web server. Below is my test program. The program just hangs. > > Thanks, > Khoa > ## > > Khoa - T

Re: Old Paranoia Game in Python

2005-01-09 Thread Paul McGuire
<[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > > Aahz wrote: > > Trust the computer, the computer is your friend. > > However, the computer isn't a fuckin' mind reader. > > If you're going to post source code on the usenet, don't > have lines longer than 72 characters. Otherwise you'

Re: Writing huge Sets() to disk

2005-01-10 Thread Paul McGuire
"Martin MOKREJ©" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Hi, > I have sets.Set() objects having up to 20E20 items, > each is composed of up to 20 characters. Keeping > them in memory on !GB machine put's me quickly into swap. > I don't want to use dictionary approach, as I d

Re: Old Paranoia Game in Python

2005-01-11 Thread Paul McGuire
"McBooCzech" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Newbie in Python. > I did copy the whole script form the web and save it as para1.py. I did > download pyparsing module and save it to > C:\\Python23\\Lib\\pyparsing122. > I did run following script: > > import sys > sys.pat

Re: Time script help sought!

2005-01-11 Thread Paul McGuire
"kpp9c" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > still working on it and also fixing the input data. I think for > simplicity and consistency's sake i will have *all* time values input > and output as hh:mm:ss maybe that would be easier but i have a few > thousand find and

Re: Time script help sought!

2005-01-11 Thread Paul McGuire
<[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > man, now that is beautifully done. Paul, I wish I knew about pyparsing > a while ago. I could have used it in a few projects. :) > Thanks for the compliment! I'll be the first to admit that pyparsing can be a bit persnickety in some ap

Re: Iteration over two sequences

2005-01-12 Thread Paul McGuire
"Henrik Holm" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > I am just starting to learn Python, mostly by going through the examples > in Dive Into Python and by playing around. > > Quite frequently, I find the need to iterate over two sequences at the > same time, and I have a bit

Re: counting items

2005-01-12 Thread Paul McGuire
"It's me" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Okay, I give up. > > What's the best way to count number of items in a list? > > For instance, > > a=[[1,2,4],4,5,[2,3]] > > I want to know how many items are there in a (answer should be 7 - I don't > want it to be 4) > I've

Re: Refactoring; arbitrary expression in lists

2005-01-12 Thread Paul McGuire
"Frans Englich" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > > As continuation to a previous thread, "PyChecker messages", I have a question > regarding code refactoring which the following snippet leads to: > > > > runner.py:200: Function (detectMimeType) has too many returns (11)

Re: Refactoring; arbitrary expression in lists

2005-01-13 Thread Paul McGuire
Despite the regexp alternatives, I refuse to post a pyparsing solution to this! :) -- Paul -- http://mail.python.org/mailman/listinfo/python-list

Re: List problems in C code ported to Python

2005-01-16 Thread Paul McGuire
"Lucas Raab" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > I'm done porting the C code, but now when running the script I > continually run into problems with lists. I tried appending and > extending the lists, but with no avail. Any help is much appreciated > Please see both the Py

Re: List problems in C code ported to Python

2005-01-16 Thread Paul McGuire
"Michael Hoffman" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Michael Hoffman wrote: > > Paul McGuire wrote: > >> So "A" == 'a' is true in Python, not true in C. > > I think you meant: > > > > >>>

Re: Assigning to self

2005-01-17 Thread Paul McGuire
<[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > An implementation of what you want can be found here: > http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/52558 > I think this recipe pre-dates the introduction of __new__ in Python. How about something like this (requires the nam

Re: Overloading ctor doesn't work?

2005-01-20 Thread Paul McGuire
"Kent Johnson" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > > Martin Häcker wrote: > > > >> Hi there, > >> > >> I just tried to run this code and failed miserably - though I dunno > >> why. Could any of you please enlighten me why this doesn't work? > > Here is a simpler test case.

Re: why am I getting a segmentation fault?

2005-01-21 Thread Paul McGuire
"Jay donnell" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > I have a short multi-threaded script that checks web images to make > sure they are still there. I get a segmentation fault everytime I run > it and I can't figure out why. Writing threaded scripts is new to me so > I may b

Re: default value in a list

2005-01-21 Thread Paul McGuire
"TB" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Hi, > > Is there an elegant way to assign to a list from a list of unknown > size? For example, how could you do something like: > > >>> a, b, c = (line.split(':')) > if line could have less than three fields? > > Thanks, > TB > I

Re: Startying with Python, need some pointers with manipulating strings

2005-01-27 Thread Paul McGuire
"Benji99" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > > Basically, I'm getting a htmlsource from a URL and need to > a.) find specific URLs > b.) find specific data > c.) with specific URLs, load new html pages and repeat. > > > Basically, I want to search through the whole strin

Re: ANNOUNCE: KirbyBase 1.7

2005-01-31 Thread Paul McGuire
"Jamey Cribbs" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Paul Rubin wrote: > > That's cute, especially the part about using Python expressions > > instead of SQL to express queries. I don't see anything in the info > > page about what happens when you have multiple clients upda

Re: use a regex or not?

2005-06-21 Thread Paul McGuire
Here's a hybrid solution, using pyparsing to parse your input pattern string (p), and transforming it into a regexp string. Then uses re.match using the regexp to process string (s), and then builds a dictionary from the matched groups. Download pyparsing at http://pyparsing.sourceforge.net. --

Re: how to use more than 1 __init__ constructor in a class ?

2005-06-22 Thread Paul McGuire
This recipe that I submitted to the Python Cookbook (http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/223611) describes a technique for doing this. I use the example of creating Color objects for plotting to a bitmap, using either R,G,andB values, or a single integer representing the RGB en

Re: Avoiding deadlocks in concurrent programming

2005-06-22 Thread Paul McGuire
Using an RDBMS is no cure-all for deadlocks - I can just as easily deadlock with an RDBMS as with my own threads and locks, probably easier. I try to pick up crumbs of knowledge from my co-workers, and one of the smarter ones gave me this rubric for testing for deadlocks. You need 3 things to cre

Re: List of all installed applications (XP)?

2005-06-23 Thread Paul McGuire
Get Tim Golden's wmi module (http://tgolden.sc.sabren.com/python/wmi.html). I recently had to help my brother remove some spyware, and so I used some of the example that came with WMI to read through the registry to extract startup keys, services, etc. Even if your users aren't sophisticated enou

Re: trouble subclassing str

2005-06-23 Thread Paul McGuire
My first thought is "make sure that subclassing str is really what you want to do." Here is a place where I have a subclass of str that really is a special kind of str: class PaddedStr(str): def __new__(cls,s,l,padc=' '): if l > len(s): s2 = "%s%s" % (s,padc*(l-len(s)))

Re: trouble subclassing str

2005-06-23 Thread Paul McGuire
Dang, that class should be: class PaddedStr(str): def __new__(cls,s,l,padc=' '): if l > len(s): s2 = "%s%s" % (s,padc*(l-len(s))) return str.__new__(cls,s2) else: return str.__new__(cls,s) -- Paul -- http://mail.python.org/mailman/listin

Re: key - key pairs

2005-06-23 Thread Paul McGuire
No need to update __getitem__, since the modified __setitem__ drops in the reverse values. But __delitem__ needs overriding, and some special guard needs to be added to __setitem__ to prevent orphaning any old value:key entries. -- Paul Here's one possible solution: class SymmetricDict(dict):

Re: trouble subclassing str

2005-06-24 Thread Paul McGuire
>From purely Python terms, there is a distinction that one of these classes (PaddedStr) is immutable, while the other is not. Python only permits immutable objects to act as dictionary keys, so this would one thing to differentiate these two approaches. But on a more abstract, implementation-inde

Re: trouble subclassing str

2005-06-24 Thread Paul McGuire
Look at the related post, on keeping key-key pairs in a dictionary. Based on our discussion in this thread, I created a subclass of dict called SymmetricDict, that, when storing symDict["A"] = 1, implicitly saves the backward looking symDict[1] = "A". I chose to inherit from dict, in part just to

Re: key - key pairs

2005-06-24 Thread Paul McGuire
Man, this is not my week! Another bug in my posted code! The posted version of SymmetricDict fails when adding an entry in which the key equals the value. First bug is in __setitem__ in which the insertion is done twice, which is wasteful but benign. The second bug is in __delitem__, which thro

Re: regex question

2005-06-25 Thread Paul McGuire
Here's a pyparsing version of this, that may be easier to maintain long term (although if you have your heart set on learning regexp's, they will certainly do the job). Note that in pyparsing, you don't have to spell out where the whitespace goes - pyparsing's default logic assumes that whitespace

Re: OO approach to decision sequence?

2005-06-26 Thread Paul McGuire
Lee C - Here is a technique for avoiding the if-elseif-elseif...-else method for building objects. It is a modified form of ChainOfResponsibility pattern, in which you have a collection of factory methods that all have a common signature, or a collection of Factory classes that all implement a "m

Re: OO approach to decision sequence?

2005-06-26 Thread Paul McGuire
Ok, I'm glad you guys liked that design pattern. Here are a few additional footnotes: 1. As George mentions, the order of the converters is *very* important, especially in this particular case. One might question whether '1+0j' would convert to a complex or an int - my first thought was to make

Re: Beginner question: Converting Single-Element tuples to list

2005-06-26 Thread Paul McGuire
('abc') is not a tuple - this is an unfortunate result of using ()'s as expression grouping *and* as tuple delimiters. To make ('abc') a tuple, you must add an extra comma, as ('abc',). >>> list( ('abc',) ) ['abc'] -- Paul -- http://mail.python.org/mailman/listinfo/python-list

Re: turn text lines into a list

2005-06-27 Thread Paul McGuire
See definition of splitlines(). (http://docs.python.org/lib/string-methods.html) -- Paul -- http://mail.python.org/mailman/listinfo/python-list

Re: Beginner question: Converting Single-Element tuples to list

2005-06-27 Thread Paul McGuire
David - I'm not getting the same results. Run this test program: --- import pyparsing as pp import sys def test(s): results = pp.OneOrMore( pp.Word(pp.alphas) ).parseString( s ) print repr(s),"->",list(results) print "Python version:", sys.version print "pyparsing version:",

Re: Beginner question: Converting Single-Element tuples to list

2005-06-27 Thread Paul McGuire
John - I just modified my test program BNF to use ZeroOrMore instead of OneOrMore, and parsed an empty string. Calling list() on the returned results gives an empty list. What version of pyparsing are you seeing this None/object/list behavior? -- Paul -- http://mail.python.org/mailman/listinf

Re: Beginner question: Converting Single-Element tuples to list

2005-06-27 Thread Paul McGuire
Modified version of test program, to handle empty strings -> empty lists. import pyparsing as pp import sys def test(s): results = pp.ZeroOrMore( pp.Word(pp.alphas) ).parseString( s ) print repr(s),"->",list(results) print "Python version:", sys.version print "pyparsing version:", pp.__v

Re: OO refactoring trial ??

2005-06-28 Thread Paul McGuire
Lee, Interesting idea, but I think the technique of "inherit from MF to automatically add class to the test chain" is a gimmick that wont scale. Here are some things to consider: - I'm not keen on the coupling of forcing your A,B,etc. classes to inherit from MF. Especially in a duck-typing lang

Re: OO refactoring trial ??

2005-06-28 Thread Paul McGuire
Lee - Bruce Eckel's observation: "the above scaffolding of Obstacle, Player and GameElementFactory (which was translated from the Java version of this example) is unnecessary - it's only required for languages that have static type checking. As long as the concrete Python classes follow the form

Re: Beginner question: Converting Single-Element tuples to list

2005-06-29 Thread Paul McGuire
Steve - Good catch - in v1.3, I added some Unicode support for pyparsing, although I have not gotten much feedback that anyone is using it, or how well it works. So it is preferable to test against basestring instead of str. -- Paul -- http://mail.python.org/mailman/listinfo/python-list

Re: multi regexp analyzer ? or how to do...

2005-06-30 Thread Paul McGuire
I'd propose a pyparsing implementation, but you don't give us many specifics. Is there any chance you could post some sample data, and one or two of the regexps you are using for matching? -- Paul -- http://mail.python.org/mailman/listinfo/python-list

Re: Escaping commas within parens in CSV parsing?

2005-06-30 Thread Paul McGuire
Well, this doesn't have the terseness of an re solution, but it shouldn't be hard to follow. -- Paul #~ This is a very crude first pass. It does not handle nested #~ ()'s, nor ()'s inside quotes. But if your data does not #~ stray too far from the example, this will probably do the job. #~ Down

Re: map/filter/reduce/lambda opinions and background unscientific mini-survey

2005-07-01 Thread Paul McGuire
I have never written a line of Lisp or Scheme, so it took me a while to grok "lambda" as a synonym for "expression to be evaluated later". I then thought it was similar to Smalltalk's functional closures, since you can define local arguments at the beginning of the block, and then write the body o

Re: f*cking re module

2005-07-05 Thread Paul McGuire
Your elaboration on what problem you are actually trying to solve gave me some additional insights into your question. It looks like you are writing a Python-HTML templating system, by embedding Python within HTML using ... tags. As many may have already guessed, I worked up a pyparsing treatment

Re: f*cking re module

2005-07-05 Thread Paul McGuire
Forgot to mention: Download pyparsing at http://pyparsing.sourceforge.net. -- Paul -- http://mail.python.org/mailman/listinfo/python-list

Re: passing arguments to a function - do I need type ?

2005-07-10 Thread Paul McGuire
Is getCenter a function? If so, you need to invoke distance using: dist = self.distance( n.getCenter(), newElement ) Of course, that is assuming that newElement is a local variable of type list/tuple/etc. -- Paul -- http://mail.python.org/mailman/listinfo/python-list

Re: inheritance

2005-07-10 Thread Paul McGuire
I'm not intimate with Python's C/C++ implementation, but is it possible that your modified code may not be implementation portable? For instance, if some calculation of the size of the object is required, inherited classes may layout data differently than contained classes would, especially if cla

Re: Parsing html :: output to comma delimited

2005-07-16 Thread Paul McGuire
Pyparsing includes a sample program for extracting URLs from web pages. You should be able to adapt it to this problem. Download pyparsing at http://pyparsing.sourceforge.net -- Paul -- http://mail.python.org/mailman/listinfo/python-list

pyparsing 1.3.2 released

2005-07-25 Thread Paul McGuire
"The best laid plans o' mice an' men / Gang aft a-gley" So said Robert Burns (who really should do something about that speech impediment!). And so said I about 6 weeks ago, when I thought that I would leave pyparsing alone for awhile, after the 1.3.1 release. Well, here we are, and I'm announci

Re: pyparsing 1.3.2 released

2005-07-25 Thread Paul McGuire
Garn! Twa' the de'ils wairk! I wad be laith to misquo' the Sco'ish Bard! I was trying to make sure I spelled "a-gley" - I lapsed into the common, but incorrect, quotation. (http://www.robertburns.org/works/75.shtml) Thanks! -- Paul -- http://mail.python.org/mailman/listinfo/python-list

Re: searching string url

2005-07-28 Thread Paul McGuire
Dave - Check out the URL extractor example that ships with pyparsing. It handles many kinds of URL formats. Download pyparsing at pyparsing.sourceforge.net. -- Paul -- http://mail.python.org/mailman/listinfo/python-list

Re: On fighting fire with fire...

2005-07-28 Thread Paul McGuire
Sounds more like fighting fire with... water? Sounds good to me. -- Paul -- http://mail.python.org/mailman/listinfo/python-list

Re: Regex for nested {}

2005-07-28 Thread Paul McGuire
Or use pyparsing, and do both at the same time (that spark example looks like a lot of work!). Download pyparsing at http://pyparsing.sourceforge.net. -- Paul from pyparsing import * text = """ outer { inner1 { ...1 } inner2 { ...2 } } simple { ...3 } null {}

Re: HTML Scraping??

2005-07-30 Thread Paul McGuire
There are several HTML scraping examples that ship with pyparsing, including a URL extractor, temperature display, and NTP server extractor (this last is probably closest to your question). Download pyparsing at http://pyparsing.sourceforge.net. -- Paul -- http://mail.python.org/mailman/listinf

Re: The ONLY thing that prevents me from using Python

2005-08-05 Thread Paul McGuire
Just because a hosting service doesn't list Python on their web page doesn't mean that it's not available. My company's service (LunarPages) supports Python, and only recently has it started appearing on their online literature. Once you find your service based on price/support/etc., send them an

Re: Help with Regular Expressions

2005-08-10 Thread Paul McGuire
If your re demands get more complicated, you could take a look at pyparsing. The code is a bit more verbose, but many find it easier to compose their expressions using pyparsing's classes, such as Literal, OneOrMore, Optional, etc., plus a number of built-in helper functions and expressions, inclu

Re: Documentation

2005-08-10 Thread Paul McGuire
Get epydoc from SourceForge (http://epydoc.sourceforge.net/). It will auto-generate beautiful HTML doc pages for your Python classes, using the information you have inserted as the doc strings for your classes and methods. I use it to generate the pyparsing documentation, and it works very well f

Re: Help with Regular Expressions

2005-08-10 Thread Paul McGuire
The pyparsing distribution includes epydoc-generated class documentation, and a few example programs. Dave Kuhlman has a nice HOWTO at http://www.rexx.com/~dkuhlman/python_201/python_201.html#SECTION00760 Drop me a note if you are looking for some specific tips or techniques. (I'

Re: How do these Java concepts translate to Python?

2005-08-11 Thread Paul McGuire
Please look through this example code, and the comments. If I've misspoken, please anyone correct my errors. -- Paul class OldStyleClass: """A definition of an old style class.""" pass class NewStyleClass(object): """Note that NewStyleClass explicitly inherits from object. This

Re: How do these Java concepts translate to Python?

2005-08-11 Thread Paul McGuire
Instance variables are typically defined in __init__(), but they can be added to an object anywhere. The only exception is when defining the magic __slots__ class variable to pre-define what the allowed instance variables can be. class A: pass a = A() a.instVar1 = "hoo-ah" a.instVar2 = "another

Re: simpli int/str problem

2005-08-12 Thread Paul McGuire
I just did this sort of thing the other day! Your database only accepts ints for BH, but remember, you are building an SQL *string* to be executed. To show SQL that your BH value is an int, not a string, do not enclose it in quotes. (Another style hint: don't name dict's "dict", as this will mas

Re: Where can be a problem?

2005-08-12 Thread Paul McGuire
Try this, its a bit more readable than your re. from pyparsing import Word,nums,Literal,replaceWith data1='' # a number is a word composed of nums, that is, the digits 0-9 # your search string is looking for a number between an '=' and '&' EQUALS = Literal("=") AMPER = Literal("&") number =

Re: Printing literal text of an argument

2005-08-13 Thread Paul McGuire
Rex - If what you are looking for is a monitor of calls to a certain function, check out this decorator example from the Python Wiki: http://wiki.python.org/moin/PythonDecoratorLibrary?highlight=%28Decorator%29#head-d4ce77c6d6e75aad25baf982f6fec0ff4b3653f4 This will allow you to very quickly tur

Re: How can I exclude a word by using re?

2005-08-15 Thread Paul McGuire
Given the example re that you've been trying to get working, here is a pyparsing approach that might be more, um, approachable. Unfortunately, since I don't have the URL of the page you are working with, I'm unable to test this before posting. Good luck, -- Paul # getMP3s.py # get pyparsing at ht

Re: How can I exclude a word by using re?

2005-08-16 Thread Paul McGuire
Just as with re you were using "?P" to assign the matching text to the variable "xxx", pyparsing allows you to associate a name with an element of your grammar using setResultsName. Here is your original re: r=re.compile(ur'valign=top>(?P­­\d{1,2})]*­>­\s{0,2}' ur'' ur'(?P.+)',re.UNICO­­DE|re.IG

Re: How can I exclude a word by using re?

2005-08-16 Thread Paul McGuire
Oof! That should be: mp3entry = valign + number.setResultsName("number"­­) + tdEnd + \ tdStart + SkipTo(aStart) + aStart + \ SkipTo(tdEnd).setResultsName("n­ame") + tdEnd -- http://mail.python.org/mailman/listinfo/python-list

Re: looping list problem

2005-08-16 Thread Paul McGuire
Well, you are returning prematurely from a for loop, so that is why you are only getting the first value. Its just like: for i in range(100): return i It doesn't matter how big the range is you are iterating over, you'll return on the first element and that's it. If what you want is the

Re: How can I exclude a word by using re?

2005-08-16 Thread Paul McGuire
I just reviewed what the re "\s" signifies: whitespace. This is easy, pyparsing ignores all intervening whitespace by default. So mp3Entry simplfies to: mp3entry = valign + number.setResultsName("number"­­­) + tdEnd + \ tdStart + aStart + \ SkipTo(tdEnd).setResultsName("­

Re: BeautifulSoup

2005-08-19 Thread Paul McGuire
Steve - Is there a chance you could post a before and after example, so we can see just what you are trying to do instead of talking conceptually all around it and making us guess? If you are just doing some spot translations of specific values in an HTML file, you can probably get away with a si

Re: BeautifulSoup

2005-08-19 Thread Paul McGuire
Here's a pyparsing program that reads my personal web page, and spits out HTML with all of the HREF's reversed. -- Paul (Download pyparsing at http://pyparsing.sourceforge.net.) from pyparsing import Literal, quotedString import urllib LT = Literal("<") GT = Literal(">") EQUALS = Literal("=")

Re: BeautifulSoup

2005-08-19 Thread Paul McGuire
Mike - Thanks for asking. Typically I hang back from these discussions of parsing HTML or XML (*especially* XML), since there are already a number of parsers out there that can handle the full language syntax. But it seems that many people trying to parse HTML aren't interested in fully parsing a

Re: regular expressions use

2005-08-22 Thread Paul McGuire
Perhaps a bit more verbose than your Perl regexp, here is a decoder using pyparsing. -- Paul # download pyparsing at http://pyparsing.sourceforge.net from pyparsing import Word,Combine # define grammar for matching encoded characters hexnums = "0123456789ABCDEFabcdef" encodedChar = Combine( "%"

Re: Sanitizing untrusted code for eval()

2005-08-23 Thread Paul McGuire
Here's the pyparsing rendition - about 24 lines of code, and another 30 for testing. For reference, here's the JSON "bnf": object { members } {} members string : value members , string : value array [ elements ] [] elements value elements , value value string

Re: Nested Regex Conditionals

2005-08-23 Thread Paul McGuire
This works (note relocated right paren at (?(second) ): #!/usr/bin/env python import re original_pattern = re.compile(r""" (?P(first)) (?(first) (?P(second)) ) (?(second) (?P(third)) ) """, re.VERBOSE) pattern = re.compile(r""" (?P(first))

Re: Reading just a few lines from a text file

2005-08-23 Thread Paul McGuire
Are you sure this is really slowing down your program? "Many hundreds of lines" is not nearly enough to start Python breathing hard. I have been really impressed with just how quickly Python is able to do file input and processing, zipping through whole megs of data in just seconds. How are you

Re: minimalist regular expression

2005-08-26 Thread Paul McGuire
Google for "optimized regexp" returns: http://laurent.riesterer.free.fr/regexp/make-regexp.html http://search.cpan.org/~dankogai/Regexp-Optimizer-0.15/ There are several more links, but all appear to be written in languages other than Python. Perhaps you could port one of them. It also seems tha

Re: change date format

2005-08-31 Thread Paul McGuire
Oh, please! Even the most lopsided, opinionated, um, person could have tried, oh, maybe, "time" as a possible module for this function? What next? "Is there a module or class that will convert 'I have no shame. ' to upper case, AND trim the trailing whitespace?" (Hint: it has to do with 'strin

Re: Improving my text processing script

2005-08-31 Thread Paul McGuire
Even though you are using re's to try to look for specific substrings (which you sort of fake in by splitting on "Identifier", and then prepending "Identifier" to every list element, so that the re will match...), this program has quite a few holes. What if the word "Identifier" is inside one of t

Re: graphical or flow charting design aid for python class development?

2005-09-01 Thread Paul McGuire
It's not free, but it is pretty cheap considering all it can do. Check out Enterprise Architect (with the free add-in for Python) from www.sparxsystems.com.au. Pro version license is US$180 or so, but they may have a student license for less that you could use. -- Paul -- http://mail.python.or

  1   2   3   4   5   6   7   8   9   10   >