> > > >Is there a command like more(1) or less(1) in python to display
> > > >the output of a command (e.g. dir()) one page at a time?
You could always write your own ...
eg:
def page(it, numLines=20):
if isinstance(it, dict):
it = it.iteritems()
for i, x in enumerate(it):
prin
> but how do i overwrite a line value with another value ?
>
> i mean, how do go to, say, line 3 of a text file and replace
> what is written on line 3 with something else?
You can't do it directly easily unless the new version
happens to be the exact same length as the original.
In practice you
> xterm is a pretty old console. Even so, you do have access to a
> ...
> command line switches for xterm to add scrollbars if you need.
The best scroll bars ever invented IMHO, much more powerful and
controllable than those in OS X or Windoze, even better then the
OpenLook scrollers of yesterye
i get it. manipulate everything while it is read.
make my changes and use writelines(list from readlines earlier)
so i kinda just hold everything in the list until i overwrite the
original. thats great. my file is only 8 lines long. no problem
thanks a lot ! Seems easy now.
-shawn
On 07/25/2005 04:
On Mon, 25 Jul 2005, nephish wrote:
> i know how to read the lines of a txt file.
> i know how to write a txt file.
>
> but how do i overwrite a line value with another value ?
>
> i mean, how do go to, say, line 3 of a text file and replace what is
> written on line 3 with something else?
Hi N
Liam -
I made some changes and timed them, I think this problem is solvable. (All
timings are done using your data, on a P4 800MHz laptop.)
1. Baseline, the current state, in the parser code you sent me:
bracketGroup << ( pp.Group( LBRACE + ( pp.empty ^ pp.OneOrMore(assignment) ^
pp.OneOrMore(i
One other thing, Liam. Download the latest version of pyparsing (1.3.2),
and make this change to the assignment statement:
assignment << pp.Dict( pp.Group( LHS + EQUALS + RHS ) )
Now you can write clean-looking code like:
test = """j = { line = { foo = 10 bar = 20 } } }"""
res = assignment.par
Liam -
The two arguments to Word work this way:
- the first argument lists valid *initial* characters
- the second argument lists valid *body* or subsequent characters
For example, in the identifier definition,
identifier = pp.Word(pp.alphas, pp.alphanums + "_/:.")
identifiers *must* start wit
Liam -
Could you e-mail me your latest grammar? The last version I had includes
this definition for RHS:
RHS << ( pp.dblQuotedString.setParseAction(pp.removeQuotes) ^
identifier ^
integer ^
pp.Group( LBRACE + pp.ZeroOrMore( assignment ^ RHS ) + RBRACE ) )
What happens
Liam -
I just uploaded an update to pyparsing, version 1.3.2, that should fix the
problem with using nested Dicts. Now you won't need to use [0] to
dereference the "0'th" element, just reference the nested elements as a.b.c,
or a["b"]["c"].
-- Paul
-Original Message-
From: Liam Clarke
Hi Paul,
That is fantastic. It works, and using that pp.group is the key with the nested braces.
I just ran this on the actual file after adding a few more possible
values inside the group, and it parsed the entire header structure
rather nicely.
Now this will probably sound silly, but from th
Liam -
Great, this sounds like it's coming together. Don't be discouraged, parsing
text like this has many forward/backward steps.
As far as stopping after one assignent, well, you might kick yourself over
this, but the answer is that you are no longer parsing just a single
assignment, but a lis
> > >Is there a command like more(1) or less(1) in python to display
> > >the output of a command (e.g. dir()) one page at a time?
> >
> >
> > How are you using dir() ?
> >
> > Is it in the "DOS Window" ?
> > One option would be to just get a better console.
>
>I am using Python 2.4 on RedHat Linux
Hey there,
kinda newbie question here.
i know how to read the lines of a txt file.
i know how to write a txt file.
but how do i overwrite a line value with another value ?
i mean, how do go to, say, line 3 of a text file and replace
what is written on line 3 with something else?
thanks
<><
Hi Paul,
Well various tweaks and such done, it parses perfectly, so much thanks,
I think I now have a rough understanding of the basics of pyparsing.
Now, onto the fun part of optimising it. At the moment, I'm looking at
2 - 5 minutes to parse a 2000 line country section, and that's with
psyco.
15 matches
Mail list logo