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: 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

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: 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

[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

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

[ANN]littletable 0.3 release

2010-10-24 Thread Paul McGuire
Announcing the 0.3 release of littletable (the module formerly known as dulce). The version includes (thanks to much help from Colin McPhail, thanks Colin!): - support for namedtuples as table objects - Python 3 compatibility - Table.pivot() to summarize record counts by 1 or 2 table attributes l

ANN: dulce 0.1 - in-memory schema-less relational database

2010-10-17 Thread Paul McGuire
dulce is a syntactic "sweet" wrapper for managing collections of Python objects like relational tables. No schema definition is used; instead table columns are introspected from the attributes of objects inserted into the table, and inferred from index and query parameters. dulce's Tables can be:

Re: mutate dictionary or list

2010-09-08 Thread Paul McGuire
On Sep 7, 7:05 am, Baba wrote: > Hi > > I am working on an exercise which requires me to write a funtion that > will check if a given word can be found in a given dictionary (the > hand). > > def is_valid_word(word, hand, word_list): >     """ >     Returns True if word is in the word_list and is

Re: Tag parsing in python

2010-08-29 Thread Paul McGuire
On Aug 28, 11:23 pm, Paul McGuire wrote: > On Aug 28, 11:14 am, agnibhu wrote: > > > > > > > Hi all, > > > I'm a newbie in python. I'm trying to create a library for parsing > > certain keywords. > > For example say I've key words l

Re: Tag parsing in python

2010-08-28 Thread Paul McGuire
On Aug 28, 11:14 am, agnibhu wrote: > Hi all, > > I'm a newbie in python. I'm trying to create a library for parsing > certain keywords. > For example say I've key words like abc: bcd: cde: like that... So the > user may use like > abc: How are you bcd: I'm fine cde: ok > > So I've to extract the

Re: Is '[' a function or an operator or an language feature?

2010-07-17 Thread Paul McGuire
On Jul 16, 12:01 pm, Peng Yu wrote: > I mean to get the man page for '[' like in the following code. > > x=[1,2,3] > > But help('[') doesn't seem to give the above usage. > > ### > Mutable Sequence Types > ** > > List objects support additional operations that allow in-

Re: nicer way to remove prefix of a string if it exists

2010-07-14 Thread Paul McGuire
On Jul 13, 6:49 pm, News123 wrote: > I wondered about a potentially nicer way of removing a prefix of a > string if it exists. > Here is an iterator solution: from itertools import izip def trim_prefix(prefix, s): i1,i2 = iter(prefix),iter(s) if all(c1==c2 for c1,c2 in izip(i1,i2)):

Re: The real problem with Python 3 - no business case for conversion (was "I strongly dislike Python 3")

2010-07-07 Thread Paul McGuire
On Jul 6, 3:30 am, David Cournapeau wrote: > On Tue, Jul 6, 2010 at 4:30 AM, D'Arcy J.M. Cain wrote: > > One thing that would be very useful is how to maintain something that > works on 2.x and 3.x, but not limiting yourself to 2.6. Giving up > versions below 2.6 is out of the question for most p

Re: GAE + recursion limit

2010-07-02 Thread Paul McGuire
> Does anyone have any clue what that might be? > Why the problem is on GAE (even when run locally), when command line > run works just fine (even with recursion limit decreased)? Can't explain why you see different behavior on GAE vs. local, but it is unusual for a "small" translator to flirt wit

Re: automate minesweeper with python

2010-06-30 Thread Paul McGuire
On Jun 30, 6:39 pm, Jay wrote: > I would like to create a python script that plays the Windows game > minesweeper. > > The python code logic and running minesweeper are not problems. > However, "seeing" the 1-8 in the minesweeper map and clicking on > squares is. I have no idea how to proceed. Yo

[ANN] pyparsing 1.5.3 released

2010-06-24 Thread Paul McGuire
I'm happy to announce that a new release of pyparsing is now available, version 1.5.3. It has been almost a year and a half since 1.5.2 was released, but pyparsing has remained pretty stable. I believe I have cleaned up the botch-job I made in version 1.5.2 of trying to support both Python 2.x an

Re: Need some Python 3 help

2010-05-25 Thread Paul McGuire
On May 25, 8:58 pm, Benjamin Peterson wrote: > Paul McGuire austin.rr.com> writes: > > > In this section of code, instring is a string, loc is an int, and wt > > is a string.  Any clues why instring[loc] would be evaluating as int? > > (I am unfortunately dependent o

Need some Python 3 help

2010-05-25 Thread Paul McGuire
I was teetering on the brink of releasing Pyparsing 1.5.3 (with some nice new examples and goodies), when I saw that I had recently introduced a bug in the Python 3 compatible version. Here is the stacktrace as reported on SF: Traceback (most recent call last): File "testcase.py", line 11, in re

condition and True or False

2010-05-02 Thread Paul McGuire
While sifting through some code looking for old "x and y or z" code that might better be coded using "y if x else z", I came across this puzzler: x = and True or False What is "and True or False" adding to this picture? The boolean expression part is already evaluating to a boolean, so I do

Re: Usable street address parser in Python?

2010-04-18 Thread Paul McGuire
On Apr 17, 2:23 pm, John Nagle wrote: >    Is there a usable street address parser available?  There are some > bad ones out there, but nothing good that I've found other than commercial > products with large databases.  I don't need 100% accuracy, but I'd like > to be able to extract street name

Re: Tough sorting problem: or, I'm confusing myself

2010-04-11 Thread Paul McGuire
On Apr 9, 10:03 am, david jensen wrote: > Hi all, > > I'm trying to find a good way of doing the following: > > Each n-tuple in combinations( range( 2 ** m ), n ) has a corresponding > value n-tuple (call them "scores" for clarity later). I'm currently > storing them in a dictionary, by doing: > >

Re: Confused by slash/escape in regexp

2010-04-11 Thread Paul McGuire
On Apr 11, 5:43 pm, andrew cooke wrote: > Is the third case here surprising to anyone else?  It doesn't make > sense to me... > > Python 2.6.2 (r262:71600, Oct 24 2009, 03:15:21) > [GCC 4.4.1 [gcc-4_4-branch revision 150839]] on linux2 > Type "help", "copyright", "credits" or "license" for more in

Re: Python and Regular Expressions

2010-04-10 Thread Paul McGuire
On Apr 10, 8:38 pm, Paul Rubin wrote: > The impression that I have (from a distance) is that Pyparsing is a good > interface abstraction with a kludgy and slow implementation.  That the > implementation uses regexps just goes to show how kludgy it is.  One > hopes that someday there will be a more

Re: Dynamically growing an array to implement a stack

2010-04-08 Thread Paul McGuire
On Apr 8, 3:21 pm, "M. Hamed" wrote: > I have trouble with some Python concept. The fact that you can not > assign to a non-existent index in an array. For example: > > a = [0,1] > a[2] => Generates an error > > I can use a.append(2) but that always appends to the end. Sometimes I > want t

Re: s-expression parser in python

2010-04-06 Thread Paul McGuire
On Apr 6, 7:02 pm, James Stroud wrote: > Hello All, > > I want to use an s-expression based configuration file format for a > python program I'm writing. Does anyone have a favorite parser? > The pyparsing wiki includes this parser on its Examples page: http://pyparsing.wikispaces.com/file/view/s

Re: Recommend Commercial graphing library

2010-04-06 Thread Paul McGuire
On Apr 6, 11:05 am, AlienBaby wrote: > The requirement for a commercial license comes down to being > restricted to not using any open source code. If it's an open source > license it can't be used in our context. You may be misunderstanding this issue, I think you are equating "open source" with

Re: vars().has_key() question about how working .

2010-04-04 Thread Paul McGuire
On Apr 4, 3:42 am, "catalinf...@gmail.com" wrote: > Hi everyone . > My questions is "why vars().has_key('b') is False ?' > I expecting to see "True" because is a variable ... > Thanks Yes, 'b' is a var, but only within the scope of something(). See how this is different: >>> def sth(): ... b

Re: C-style static variables in Python?

2010-04-02 Thread Paul McGuire
On Apr 1, 5:34 pm, kj wrote: > When coding C I have often found static local variables useful for > doing once-only run-time initializations.  For example: > Here is a decorator to make a function self-aware, giving it a "this" variable that points to itself, which you could then initialize from

Re: Generating text from a regular expression

2010-03-31 Thread Paul McGuire
On Mar 31, 5:49 am, Nathan Harmston wrote: > Hi everyone, > > I have a slightly complicated/medium sized regular expression and I > want to generate all possible words that it can match (to compare > performance of regex against an acora based matcher). The pyparsing wiki Examples page includes t

Re: file seek is slow

2010-03-09 Thread Paul McGuire
This is a pretty tight loop: for i in xrange(100): f1.seek(0) But there is still a lot going on, some of which you can lift out of the loop. The easiest I can think of is the lookup of the 'seek' attribute on the f1 object. Try this: f1_seek = f1.seek for i in xrange(100):

Re: Problem with regular expression

2010-03-07 Thread Paul McGuire
On Mar 7, 4:32 am, Joan Miller wrote: > I would to convert the first string to upper case. But this regular > expression is not matching the first string between quotes. > Is using pyparsing overkill? Probably. But your time is valuable, and pyparsing let's you knock this out in less time than i

Re: How to efficiently extract information from structured text file

2010-02-18 Thread Paul McGuire
On Feb 17, 7:38 pm, Steven D'Aprano wrote: > On Wed, 17 Feb 2010 17:13:23 -0800, Jonathan Gardner wrote: > > And once you realize that every program is really a compiler, then you > > have truly mastered the Zen of Programming in Any Programming Language > > That Will Ever Exist. > > In the same w

Re: How to efficiently extract information from structured text file

2010-02-17 Thread Paul McGuire
On Feb 16, 5:48 pm, Imaginationworks wrote: > Hi, > > I am trying to read object information from a text file (approx. > 30,000 lines) with the following format, each line corresponds to a > line in the text file.  Currently, the whole file was read into a > string list using readlines(), then use

Re: pyparsing wrong output

2010-02-12 Thread Paul McGuire
On Feb 12, 6:41 pm, "Gabriel Genellina" wrote: > En Fri, 12 Feb 2010 10:41:40 -0300, Eknath Venkataramani   > escribió: > > > I am trying to write a parser in pyparsing. > > Help Me.http://paste.pocoo.org/show/177078/is the code and this is   > > input > > file:http://paste.pocoo.org/show/177076/

Re: How to measure elapsed time under Windows?

2010-02-10 Thread Paul McGuire
On Feb 10, 2:24 am, Dennis Lee Bieber wrote: > On Tue, 9 Feb 2010 21:45:38 + (UTC), Grant Edwards > declaimed the following in > gmane.comp.python.general: > > > Doesn't work.  datetime.datetime.now has granularity of > > 15-16ms. > > > Intervals much less that that often come back with a del

Re: How to measure elapsed time under Windows?

2010-02-09 Thread Paul McGuire
On Feb 9, 10:10 am, Grant Edwards wrote: > Is there another way to measure small periods of elapsed time > (say in the 1-10ms range)? > On Feb 9, 10:10 am, Grant Edwards wrote: > Is there another way to measure small periods of elapsed time > (say in the 1-10ms range)? > I made repeated calls to

Re: How to print all expressions that match a regular expression

2010-02-07 Thread Paul McGuire
On Feb 6, 1:36 pm, "hzh...@gmail.com" wrote: > Hi, > > I am a fresh man with python. I know there is regular expressions in > Python. What I need is that given a particular regular expression, > output all the matches. For example, given “[1|2|3]{2}” as the regular > expression, the program should

Re: parsing an Excel formula with the re module

2010-01-14 Thread Paul McGuire
I never represented that this parser would handle any and all Excel formulas! But I should hope the basic structure of a pyparsing solution might help the OP add some of the other features you cited, if necessary. It's actually pretty common to take an incremental approach in making such a parser,

Re: parsing an Excel formula with the re module

2010-01-13 Thread Paul McGuire
On Jan 5, 1:49 pm, Tim Chase wrote: > vsoler wrote: > > Hence, I need toparseExcel formulas. Can I do it by means only of re > > (regular expressions)? > > > I know that for simple formulas such as "=3*A7+5" it is indeed > > possible. What about complex for formulas that include functions, > > she

Re: Regex help needed!

2009-12-22 Thread Paul McGuire
On Dec 21, 5:38 am, Oltmans wrote: > Hello,. everyone. > > I've a string that looks something like > > lksjdfls kdjff lsdfs sdjfls =   "amazon_35343433">sdfsdwelcome > > > From above string I need the digits within the ID attribute. For > example, required output from above string is

Re: How to create a docstring for a module?

2009-12-06 Thread Paul McGuire
On Dec 6, 7:43 am, Steven D'Aprano wrote: > On Sun, 06 Dec 2009 06:34:17 -0600, Tim Chase wrote: > > I've occasionally wanted something like this, and have found that it can > > be done by manually assigning to __doc__ (either at the module-level or > > classes) which can make some documentation b

Re: trouble with regex?

2009-10-08 Thread Paul McGuire
On Oct 8, 11:42 am, MRAB wrote: > inhahe wrote: > > Can someone tell me why this doesn't work? > > > colorre = re.compile ('(' > >                         '^' > >                        '|' > >                         '(?:' > >                            '\x0b(?:10|11|12|13|14|15|0\\d|\\d)' > >  

Re: bug with itertools.groupby?

2009-10-07 Thread Paul McGuire
On Oct 6, 6:06 pm, Kitlbast wrote: > > grouped acc:  61 > grouped acc:  64 > grouped acc:  61 > > am I doing something wrong? sort first, then groupby. -- http://mail.python.org/mailman/listinfo/python-list

Re: Regular expression to structure HTML

2009-10-02 Thread Paul McGuire
On Oct 2, 12:10 am, "504cr...@gmail.com" <504cr...@gmail.com> wrote: > I'm kind of new to regular expressions, and I've spent hours trying to > finesse a regular expression to build a substitution. > > What I'd like to do is extract data elements from HTML and structure > them so that they can more

Re: Are min() and max() thread-safe?

2009-09-17 Thread Paul McGuire
On Sep 16, 11:33 pm, Steven D'Aprano wrote: > I have two threads, one running min() and the other running max() over > the same list. I'm getting some mysterious results which I'm having > trouble debugging. Are min() and max() thread-safe, or am I doing > something fundamentally silly by having t

Re: Retrieve url's of all jpegs at a web page URL

2009-09-15 Thread Paul McGuire
On Sep 15, 11:32 pm, Stefan Behnel wrote: > Also untested: > >         from lxml import html > >         doc = html.parse(page_url) >         doc.make_links_absolute(page_url) > >         urls = [ img.src for img in doc.xpath('//img') ] > > Then use e.g. urllib2 to save the images. Looks similar

Re: Where regexs listed for Python language's tokenizer/lexer?

2009-09-12 Thread Paul McGuire
On Sep 12, 1:10 am, Chris Seberino wrote: > Where regexs listed for Python language's tokenizer/lexer? > > If I'm not mistaken, the grammar is not sufficient to specify the > language > you also need to specify the regexs that define the tokens > right?..where is that? I think the OP is askin

Re: Smallest float different from 0.0?

2009-09-07 Thread Paul McGuire
On Sep 7, 9:47 am, kj wrote: > Is there some standardized way (e.g. some "official" module of such > limit constants) to get the smallest positive float that Python > will regard as distinct from 0.0? > > TIA! > > kj You could find it for yourself: >>> for i in range(400): ...if 10**-i == 0:

Re: Something confusing about non-greedy reg exp match

2009-09-07 Thread Paul McGuire
On Sep 6, 11:23 pm, Ben Finney wrote: > George Burdell writes: > > I want to find every occurrence of "money," and for each > > occurrence, I want to scan back to the first occurrence > > of "hello." How can this be done? > > By recognising the task: not expression matching, but lexing and > pars

Re: Creating slice notation from string

2009-09-02 Thread Paul McGuire
On Sep 2, 4:55 pm, bvdp wrote: > I'm trying to NOT create a parser to do this and I'm sure that > it's easy if I could only see the light! > Well, this is a nice puzzler, better than a sudoku. Maybe a quick parser with pyparsing will give you some guidance on how to do this without a parser

Re: Is behavior of += intentional for int?

2009-08-30 Thread Paul McGuire
On Aug 30, 5:42 am, Paul McGuire wrote: > Python binds values to names. Always. In Python, "=" is not and never > could be a class operator.  In Python, any expression of LHS = RHS, > LHS is always a name, and in this statement it is being bound to some > object found by eva

Re: Is behavior of += intentional for int?

2009-08-30 Thread Paul McGuire
On Aug 30, 2:33 am, Derek Martin wrote: > THAT is why Python's behavior with regard to numerical objects is > not intuitive, and frankly bizzare to me, and I dare say to others who > find it so. > > Yes, that's right.  BIZZARE. > Can't we all just get along? I think the question boils down to "w

Re: Is behavior of += intentional for int?

2009-08-29 Thread Paul McGuire
On Aug 29, 7:45 am, zaur wrote: > Python 2.6.2 (r262:71600, Apr 16 2009, 09:17:39) > [GCC 4.0.1 (Apple Computer, Inc. build 5250)] on darwin > Type "copyright", "credits" or "license()" for more information.>>> a=1 > >>> x=[a] > >>> id(a)==id(x[0]) > True > >>> a+=1 > >>> a > 2 > >>> x[0] > > 1 >

Re: regexp help

2009-08-27 Thread Paul McGuire
On Aug 27, 1:15 pm, Bakes wrote: > If I were using the code: > > (?P[0-9]+) > > to get an integer between 0 and 9, how would I allow it to register > negative integers as well? With that + sign in there, you will actually get an integer from 0 to 9... -- Paul -- http://mail.pyth

Re: python fast HTML data extraction library

2009-07-22 Thread Paul McGuire
On Jul 22, 5:43 pm, Filip wrote: > > My library, rather than parsing the whole input into a tree, processes > it like a char stream with regular expressions. > Filip - In general, parsing HTML with re's is fraught with easily-overlooked deviations from the norm. But since you have stepped up to

Re: Override a method but inherit the docstring

2009-07-16 Thread Paul McGuire
On Jul 16, 8:01 pm, Ben Finney wrote: > Howdy all, > > The following is a common idiom:: > >     class FooGonk(object): >         def frobnicate(self): >             """ Frobnicate this gonk. """ >             basic_implementation(self.wobble) > >     class BarGonk(FooGonk): >         def frobnica

Re: c++ Source Code for acm 2004-2005 problems

2009-07-12 Thread Paul McGuire
On Jul 12, 5:24 pm, Davood Vahdati wrote: > Dear Sirs And Madams : > > it is an Acm programming competition Questions in year 2004-2005 . > could you please solve problems is question ? I  Wan't C++ Source Code > program About this questions OR Problems . thank you for your prompt > attention to t

Re: Examples of Python driven Microsoft UI Automation wanted

2009-07-09 Thread Paul McGuire
On Jul 9, 1:50 pm, DuaneKaufman wrote: > > I have used pywinauto to drive a Flash game running inside of an > > Internet Explorer browser - that's pretty GUI! > > > -- Paul > > Hi, > > Could you share some code examples? > > Thanks, > Duane (duanek (at) chorus (dot) net) I just went on a brief fi

Re: Examples of Python driven Microsoft UI Automation wanted

2009-07-09 Thread Paul McGuire
On Jul 9, 1:09 pm, DuaneKaufman wrote: > The application I wish to interact with is not my own, but an ERP > system GUI front-end. > I have used pywinauto to drive a Flash game running inside of an Internet Explorer browser - that's pretty GUI! -- Paul -- http://mail.python.org/mailman/listinfo

Re: parsing times like "5 minutes ago"?

2009-07-06 Thread Paul McGuire
On Jul 6, 7:21 pm, m...@pixar.com wrote: > I'm looking for something like Tcl's [clock scan] command which parses > human-readable time strings such as: > >     % clock scan "5 minutes ago" >     1246925569 >     % clock scan "tomorrow 12:00" >     1246993200 >     % clock scan "today + 1 fortnight

Re: Code that ought to run fast, but can't due to Python limitations.

2009-07-05 Thread Paul McGuire
On Jul 5, 3:12 am, "Hendrik van Rooyen" wrote: > > Use a dispatch dict, and have each state return the next state. > Then you can use strings representing state names, and > everybody will be able to understand the code. > > toy example, not tested, nor completed: > > protocol = {"start":initialis

Re: random number including 1 - i.e. [0,1]

2009-06-10 Thread Paul McGuire
On Jun 9, 11:23 pm, Esmail wrote: > Here is part of the specification of an algorithm I'm implementing that > shows the reason for my original query: > > vid = w * vid + c1 * rand( ) * ( pid – xid ) + c2 * Rand( ) * (pgd –xid ) (1a) > > xid = xid + vid (1b) > > where c1 and c2 are two positive con

Re: How to insert string in each match using RegEx iterator

2009-06-10 Thread Paul McGuire
On Jun 9, 11:13 pm, "504cr...@gmail.com" <504cr...@gmail.com> wrote: > By what method would a string be inserted at each instance of a RegEx > match? > Some might say that using a parsing library for this problem is overkill, but let me just put this out there as another data point for you. Pypar

Re: random number including 1 - i.e. [0,1]

2009-06-09 Thread Paul McGuire
On Jun 9, 4:33 pm, Esmail wrote: > Hi, > > random.random() will generate a random value in the range [0, 1). > > Is there an easy way to generate random values in the range [0, 1]? > I.e., including 1? > Are you trying to generate a number in the range [0,n] by multiplying a random function that

Re: networking simulator on python

2009-06-08 Thread Paul McGuire
On Jun 8, 7:18 pm, Ala wrote: > Hello everyone. > > I plan on starting to write a network simulator on python for testing a > modified version of TCP. > > I am wondering if a python network simulator exists? Also, if anyone > tried using simpy for doing a simulation. > > Thank you There was an ar

Re: I need help building a data structure for a state diagram

2009-05-25 Thread Paul McGuire
On May 24, 1:16 pm, Matthew Wilson wrote: > I'm working on a really simple workflow for my bug tracker.  I want > filed bugs to start in an UNSTARTED status.  From there, they can go to > STARTED. > I just wrote an article for the April issue of Python Magazine on how to add embedded DSL code to

Re: slice iterator?

2009-05-08 Thread Paul McGuire
On May 8, 11:14 pm, Ned Deily wrote: > In article <7xprejoswg@ruckus.brouhaha.com>, >  Paul Rubin wrote: > > > > > > > Ross writes: > > > I have a really long list that I would like segmented into smaller > > > lists. Let's say I had a list a = [1,2,3,4,5,6,7,8,

Re: string processing question

2009-04-30 Thread Paul McGuire
On Apr 30, 11:55 am, Kurt Mueller wrote: > Hi, > > on a Linux system and python 2.5.1 I have the > following behaviour which I do not understand: > > case 1> python -c 'a="ä"; print a ; print a.center(6,"-") ; b=unicode(a, > "utf8"); print b.center(6,"-")' > > ä > --ä-- > --ä--- > > Weird. What

Re: if statement, with function inside it: if (t = Test()) == True:

2009-04-24 Thread Paul McGuire
On Apr 24, 5:00 am, GC-Martijn wrote: > Hello, > > I'm trying to do a if statement with a function inside it. > I want to use that variable inside that if loop , without defining it. > > def Test(): >     return 'Vla' > > I searching something like this: > > if (t = Test()) == 'Vla': >     print t

ANN: pyparsing 1.5.2 released!

2009-04-20 Thread Paul McGuire
Well, it has been about 6 months since the release of pyparsing 1.5.1, and there have been no new functional enhancements to pyparsing. I take this as a further sign that pyparsing is reaching a development/ maturity plateau. With the help of the pyparsing community, there are some compatibility

Re: regex alternation problem

2009-04-17 Thread Paul McGuire
On Apr 17, 5:28 pm, Paul McGuire wrote: > -- Paul > > Your find pattern includes (and consumes) a leading AND trailing space > around each word.  In the first string "I am an american", there is a > leading and trailing space around "am", but the trailing space

Re: regex alternation problem

2009-04-17 Thread Paul McGuire
On Apr 17, 4:49 pm, Jesse Aldridge wrote: > import re > > s1 = "I am an american" > > s2 = "I am american an " > > for s in [s1, s2]: >     print re.findall(" (am|an) ", s) > > # Results: > # ['am'] > # ['am', 'an'] > > --- > > I want the results to be the same for each string.  What am I doin

Re: Help improve program for parsing simple rules

2009-04-17 Thread Paul McGuire
On Apr 17, 2:40 pm, prueba...@latinmail.com wrote: > On Apr 17, 11:26 am, Paul McGuire wrote: > > > > > > > On Apr 16, 10:57 am, prueba...@latinmail.com wrote: > > > > Another interesting task for those that are looking for some > > > interesting pro

Re: question about xrange performance

2009-04-17 Thread Paul McGuire
On Apr 17, 1:39 pm, _wolf wrote: > > can it be that a simple diy-class outperforms a python built-in by a > factor of 180? is there something i have done the wrong way? > omissions, oversights? do other people get similar figures? > > cheers I wouldn't say you are outperforming xrange until your

Re: Help improve program for parsing simple rules

2009-04-17 Thread Paul McGuire
On Apr 17, 1:26 pm, Aaron Brady wrote: > Hi, not to offend; I don't know your background.   Courtesy on Usenet!!! I'm going to go buy a lottery ticket! Not to worry, I'm a big boy. People have even called my baby ugly, and I manage to keep my blood pressure under control. > One thing I like >

Re: Help improve program for parsing simple rules

2009-04-17 Thread Paul McGuire
On Apr 17, 10:43 am, John Machin wrote: > > I don't see how it can handle the chained relop in the last two > testcases e. g. '0.00 LE A LE 4.00' -- unless relops are chained by > default in your parser. > John - First of all, to respect precedence of operations, higher level precedences are par

Re: Help improve program for parsing simple rules

2009-04-17 Thread Paul McGuire
On Apr 16, 10:57 am, prueba...@latinmail.com wrote: > Another interesting task for those that are looking for some > interesting problem: > I inherited some rule system that checks for programmers program > outputs that to be ported: given some simple rules and the values it > has to determine if t

Re: Automatically generating arithmetic operations for a subclass

2009-04-14 Thread Paul McGuire
On Apr 14, 4:09 am, Steven D'Aprano wrote: > I have a subclass of int where I want all the standard arithmetic > operators to return my subclass, but with no other differences: > > class MyInt(int): >     def __add__(self, other): >         return self.__class__(super(MyInt, self).__add__(other))

Re: safe eval of moderately simple math expressions

2009-04-11 Thread Paul McGuire
On Apr 11, 2:41 am, Aaron Brady wrote: > > Why do I get the feeling that the authors of 'pyparsing' are out of > breath? > What kind of breathlessness do you mean? I'm still breathing, last time I checked. The-rumors-of-my-demise-have-been-greatly-exaggerated'ly yours, -- Paul -- http://mail.

Re: safe eval of moderately simple math expressions

2009-04-09 Thread Paul McGuire
On Apr 9, 10:56 am, Joel Hedlund wrote: > Hi all! > > I'm writing a program that presents a lot of numbers to the user, and I > want to let the user apply moderately simple arithmentics to these > numbers. Joel - Take a look at the examples page on the pyparsing wiki (http:// pyparsing.wikispace

Re: python needs leaning stuff from other language

2009-04-04 Thread Paul McGuire
On Apr 3, 11:48 pm, Tim Wintle wrote: > del mylist[:] > * or * > mylist[:] = [] > * or * > mylist = [] > > which, although semantically similar are different as far as the > interpreter are concerned (since two of them create a new list): > Only the last item creates a new list of any consequence

Re: Best way to extract from regex in if statement

2009-04-04 Thread Paul McGuire
On Apr 3, 9:26 pm, Paul Rubin wrote: > bwgoudey writes: > > elif re.match("^DATASET:\s*(.+) ", line): > >         m=re.match("^DATASET:\s*(.+) ", line) > >         print m.group(1)) > > Sometimes I like to make a special class that saves the result: > >   class Reg(o

Re: List of paths

2009-04-01 Thread Paul McGuire
On Apr 1, 3:57 am, Nico Grubert wrote: > Dear Python developers > > I have the following (sorted) list. > ['/notebook', >   '/notebook/mac', >   '/notebook/mac/macbook', >   '/notebook/mac/macbookpro', >   '/notebook/pc', >   '/notebook/pc/lenovo', >   '/notebook/pc/hp', >   '/notebook/pc/sony', >

Re: How do I learn about Python & XML?

2009-03-28 Thread Paul McGuire
On Mar 28, 3:11 pm, walterbyrd wrote: > It looks like the most recent book on the subject came out eight years > ago. Also, as I understand it, the PyXML library has been deprecated. Much as I like to see new people latch onto pyparsing, XML is a pretty well-trodden path, especially now that elem

Re: split string at commas respecting quotes when string not in csv format

2009-03-27 Thread Paul McGuire
On Mar 27, 5:19 am, Tim Chase wrote: > >>  >>> import re > >>  >>> s = """a=1,b="0234,)#($)@", k="7" """ > >>  >>> rx = re.compile(r'[ ]*(\w+)=([^",]+|"[^"]*")[ ]*(?:,|$)') > >>  >>> rx.findall(s) > >>  [('a', '1'), ('b', '"0234,)#($)@"'), ('k', '"7"')] > >>  >>> rx.findall('a=1, *DODGY*SYNTAX* b=

Re: split string at commas respecting quotes when string not in csv format

2009-03-26 Thread Paul McGuire
On Mar 26, 2:51 pm, "R. David Murray" wrote: > OK, I've got a little problem that I'd like to ask the assembled minds > for help with.  I can write code to parse this, but I'm thinking it may > be possible to do it with regexes.  My regex foo isn't that good, so if > anyone is willing to help (or

Re: Is there a simple soap library for python?

2009-03-26 Thread Paul McGuire
On Mar 26, 5:17 am, "Diez B. Roggisch" wrote: > > Or maybe Jython + apache axis is a way to go for you, if it's about > quickly writing tests/prototypes against a working service. > The best utility I've found for quickly writing tests against an existing service is soapUI. Very easy to write reg

Re: How can I know if a date is prior to today?

2009-03-25 Thread Paul McGuire
On Mar 25, 8:31 am, "Giampaolo Rodola'" wrote: > Hi, > I have a date expressed in seconds. > I'd want to pretty print it as "%H:%M" if the time refers to today and > "%b%d" (month, day) if it's of yesterday or before. > Use datetime module. import time from datetime import datetime now = time.ti

Re: Bash-like brace expansion

2009-03-24 Thread Paul McGuire
On Mar 24, 12:39 pm, Peter Waller wrote: > > Maybe I might re-implement this with pyparsing and some unit tests. > In your pyparsing efforts, you might draw some insights from this regex inverter (that is, given an re such as "[AB]\d", returns "A0" through "B9") on the pyparsing wiki: http://pyp

Re: __init__ vs. __del__

2009-03-21 Thread Paul McGuire
On Mar 21, 8:37 pm, Christian Heimes wrote: > Randy Turner wrote: > > I was reading a book on Python-3 programming recently and the book stated > > that, while there is an __init__ method for initializing objects, there was > > a __del__ method but the __del__ method is not guaranteed to be call

Re: Organize large DNA txt files

2009-03-20 Thread Paul McGuire
On Mar 20, 11:59 am, Daniel Fetchinson wrote: > Have you considered using a lightweight database solution? Sqlite is a > really simple, zero configuration, server-less db and a python binding > for it comes with python itself. I'd give it a try, it will simplify > tasks like these a great deal. >

Re: get rid of duplicate elements in list without set

2009-03-20 Thread Paul McGuire
On Mar 20, 9:54 am, "thomasvang...@gmail.com" wrote: > You could use: > B=list(set(A)).sort() > Hope that helps. > T That may hurt more than help, sort() only works in-place, and does *not* return the sorted list. For that you want the global built-in sorted: >>> data = map(int,"6 1 3 2 5 2 5 4

Re: cross compile Python to Linux-ARM

2009-03-19 Thread Paul McGuire
On Mar 19, 11:54 am, jefm wrote: > Hi, > We are looking to use Python on an embedded Linux ARM system. > What I gather from googling the subject is that it is not that > straight forward (a fair amount of patching & hacking). > Nobody out there that has done it claims it is easy, which makes me >

Re: How complex is complex?

2009-03-19 Thread Paul McGuire
On Mar 19, 4:39 am, Kottiyath wrote: > > I understand that my question was foolish, even for a newbie. > I will not ask any more such questions in the future. > Gaaah! Your question was just fine, a good question on coding style. I wish more people would ask such questions so that bad habits coul

Re: How complex is complex?

2009-03-18 Thread Paul McGuire
You realize of course that these two alternatives are not equivalent. The first does what your problem statement describes, for each key in a given dict, increments the corresponding value. The second creates an entirely new dict with the modified values. Even if you were to write the second one

Re: is there an easy way to parse a nested list ?

2009-03-16 Thread Paul McGuire
On Mar 16, 4:29 am, Vlastimil Brom wrote: > 2009/3/16 Vlastimil Brom : > > > > > 2009/3/16 Stef Mientki : > >> hello, > > >> I need to parse a nested list, given as a string, like this > > >> line = " A  [  B  [ C+2 ] + 3 ] " > > > ... > > >> thanks, > >> Stef > > > there is a "nestedExpr" (and pr

Re: Is this type of forward referencing possible?

2009-03-15 Thread Paul McGuire
On Mar 15, 6:33 am, "andrew cooke" wrote: > someone else has answered this, but an extra trick that is sometimes > useful is that while there is no forward referencing you can often exploit > late binding and evaluation order. > > your example will not work because code at the class level is evalu

Re: converting a string to a function parameter

2009-03-13 Thread Paul McGuire
On Mar 13, 11:46 am, Aaron Brady wrote: > On Mar 13, 2:52 am, koranthala wrote: > > > Hi, > >     Is it possible to convert a string to a function parameter? > > Ex: > > str = 'True, type=rect, sizes=[3, 4]' > > and I should be able to use it as: > > test(convert(str)) and the behaviour should be

  1   2   3   4   5   6   7   8   9   10   >