pyparsing batch file
Fabian Braennstroem
f.braennstroem at gmx.de
Sat Oct 20 06:30:21 EDT 2007
Hi Paul,
Paul McGuire wrote:
> On Oct 17, 4:47 pm, Fabian Braennstroem <f.braennstr... at gmx.de> wrote:
> <snip>
>> Unfortunately, it does not parse the whole file names with
>> the underscore and I do not know yet, how I can access the
>> line with 'define/boundary-conditions'. Every 'argument' of
>> that command should become a separate python variable!?
>> Does anyone have an idea, how I can achieve this!?
>> Regards!
>> Fabian
>
> You are trying to match "keps1500_500.dat" with the expression
> "Word(alphanums)". Since the filename contains characters other than
> alphas and numbers, you must add the remaining characters ("." and
> "_") to the expression. Try changing:
>
> write= Word(alphanums)
>
> to:
>
> write= Word(alphanums+"._")
>
>
> To help you to parse "/define/boundary-conditions in velocity-inlet 10
> 0.1 0.1 no 1", we would need to know just what these arguments are,
> and what values they can take. I'll take a wild guess, and propose
> this:
>
> real = Combine(integer + "." + integer)
> defineBoundaryConditions = "/define/boundary-conditions" + \
> oneOf("in out inout")("direction") + \
> Word(alphanums+"-")("conditionName") + \
> integer("magnitude") + \
> real("initialX") + \
> real("initialY") + \
> oneOf("yes no")("optional") + \
> integer("normal")
>
> (Note I am using the new notation for setting results names,
> introduced in 1.4.7 - simply follow the expression with ("name"),
> instead of having to call .setResultsName.)
>
> And here is a slight modification to your printout routine, using the
> dump() method of the ParseResults class:
>
> for tokens in defineBoundaryConditions.searchString(data):
> print
> print "Boundary Conditions = "+ tokens.conditionName
> print tokens.dump()
> print
> print 50*"-"
>
>
> prints:
>
> Boundary Conditions = velocity-inlet
> ['/define/boundary-conditions', 'in', 'velocity-inlet', '10', '0.1',
> '0.1', 'no', '1']
> - conditionName: velocity-inlet
> - direction: in
> - initialX: 0.1
> - initialY: 0.1
> - magnitude: 10
> - normal: 1
> - optional: no
Great! Thanks for the very good explanation!
Regards!
Fabian
More information about the Python-list
mailing list