From: Brandon Harris on
I'm trying to read in and parse an ascii type file that contains
information that can span several lines.
Example:

createNode animCurveTU -n "test:master_globalSmooth";
setAttr ".tan" 9;
setAttr -s 4 ".ktv[0:3]" 101 0 163 0 169 0 201 0;
setAttr -s 4 ".kit[3]" 10;
setAttr -s 4 ".kot[3]" 10;
createNode animCurveTU -n "test:master_res";
setAttr ".tan" 9;
setAttr ".ktv[0]" 103 0;
setAttr ".kot[0]" 5;
createNode animCurveTU -n "test:master_faceRig";
setAttr ".tan" 9;
setAttr ".ktv[0]" 103 0;
setAttr ".kot[0]" 5;

I'm wanting to grab the information out in chunks, so

createNode animCurveTU -n "test:master_faceRig";
setAttr ".tan" 9;
setAttr ".ktv[0]" 103 0;
setAttr ".kot[0]" 5;

would be what my regex would grab.
I'm currently only able to grab out the first line and part of the
second line, but no more.
regex is as follows

my_regexp = re.compile("createNode\ animCurve.*\n[\t*setAttr.*\n]*")

I've run several variations of this, but none return me all of the
expected information.

Is there something special that needs to be done to have the regexp grab
any number of the setAttr lines without specification?

Brandon L. Harris


From: Rodrick Brown on
Slurp the entire file into a string and pick out the fields you need.

Sent from my iPhone 4.

On Jul 21, 2010, at 10:42 AM, Brandon Harris <brandon.harris(a)reelfx.com> wrote:

> I'm trying to read in and parse an ascii type file that contains information that can span several lines.
> Example:
>
> createNode animCurveTU -n "test:master_globalSmooth";
> setAttr ".tan" 9;
> setAttr -s 4 ".ktv[0:3]" 101 0 163 0 169 0 201 0;
> setAttr -s 4 ".kit[3]" 10;
> setAttr -s 4 ".kot[3]" 10;
> createNode animCurveTU -n "test:master_res";
> setAttr ".tan" 9;
> setAttr ".ktv[0]" 103 0;
> setAttr ".kot[0]" 5;
> createNode animCurveTU -n "test:master_faceRig";
> setAttr ".tan" 9;
> setAttr ".ktv[0]" 103 0;
> setAttr ".kot[0]" 5;
>
> I'm wanting to grab the information out in chunks, so
>
> createNode animCurveTU -n "test:master_faceRig";
> setAttr ".tan" 9;
> setAttr ".ktv[0]" 103 0;
> setAttr ".kot[0]" 5;
>
> would be what my regex would grab.
> I'm currently only able to grab out the first line and part of the second line, but no more.
> regex is as follows
>
> my_regexp = re.compile("createNode\ animCurve.*\n[\t*setAttr.*\n]*")
>
> I've run several variations of this, but none return me all of the expected information.
>
> Is there something special that needs to be done to have the regexp grab any number of the setAttr lines without specification?
>
> Brandon L. Harris
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
From: Brandon Harris on
what do you mean by slurp the entire file?
I'm trying to use regular expressions because line by line parsing will
be too slow. And example file would have somewhere in the realm of 6
million lines of code.

Brandon L. Harris

Rodrick Brown wrote:
> Slurp the entire file into a string and pick out the fields you need.
>
> Sent from my iPhone 4.
>
> On Jul 21, 2010, at 10:42 AM, Brandon Harris <brandon.harris(a)reelfx.com> wrote:
>
>
>> I'm trying to read in and parse an ascii type file that contains information that can span several lines.
>> Example:
>>
>> createNode animCurveTU -n "test:master_globalSmooth";
>> setAttr ".tan" 9;
>> setAttr -s 4 ".ktv[0:3]" 101 0 163 0 169 0 201 0;
>> setAttr -s 4 ".kit[3]" 10;
>> setAttr -s 4 ".kot[3]" 10;
>> createNode animCurveTU -n "test:master_res";
>> setAttr ".tan" 9;
>> setAttr ".ktv[0]" 103 0;
>> setAttr ".kot[0]" 5;
>> createNode animCurveTU -n "test:master_faceRig";
>> setAttr ".tan" 9;
>> setAttr ".ktv[0]" 103 0;
>> setAttr ".kot[0]" 5;
>>
>> I'm wanting to grab the information out in chunks, so
>>
>> createNode animCurveTU -n "test:master_faceRig";
>> setAttr ".tan" 9;
>> setAttr ".ktv[0]" 103 0;
>> setAttr ".kot[0]" 5;
>>
>> would be what my regex would grab.
>> I'm currently only able to grab out the first line and part of the second line, but no more.
>> regex is as follows
>>
>> my_regexp = re.compile("createNode\ animCurve.*\n[\t*setAttr.*\n]*")
>>
>> I've run several variations of this, but none return me all of the expected information.
>>
>> Is there something special that needs to be done to have the regexp grab any number of the setAttr lines without specification?
>>
>> Brandon L. Harris
>>
>>
>> --
>> http://mail.python.org/mailman/listinfo/python-list
>>

From: Brandon Harris on
At the moment I'm trying to stick with built in python modules to create
tools for a much larger pipeline on multiple OSes.

Brandon L. Harris


Eknath Venkataramani wrote:
>
>
> On Wed, Jul 21, 2010 at 8:12 PM, Brandon Harris
> <brandon.harris(a)reelfx.com <mailto:brandon.harris(a)reelfx.com>> wrote:
>
> I'm trying to read in and parse an ascii type file that contains
> information that can span several lines.
>
> Do you have to use only regex? If not, I'd certainly suggest
> 'pyparsing'. It's a pleasure to use and very easy on the eye too, if
> you know what I mean.
>
> I'm wanting to grab the information out in chunks, so
>
>
> --
> Eknath Venkataramani

From: Peter Otten on
Brandon Harris wrote:

> I'm trying to read in and parse an ascii type file that contains
> information that can span several lines.
> Example:
>
> createNode animCurveTU -n "test:master_globalSmooth";
> setAttr ".tan" 9;
> setAttr -s 4 ".ktv[0:3]" 101 0 163 0 169 0 201 0;
> setAttr -s 4 ".kit[3]" 10;
> setAttr -s 4 ".kot[3]" 10;
> createNode animCurveTU -n "test:master_res";
> setAttr ".tan" 9;
> setAttr ".ktv[0]" 103 0;
> setAttr ".kot[0]" 5;
> createNode animCurveTU -n "test:master_faceRig";
> setAttr ".tan" 9;
> setAttr ".ktv[0]" 103 0;
> setAttr ".kot[0]" 5;
>
> I'm wanting to grab the information out in chunks, so
>
> createNode animCurveTU -n "test:master_faceRig";
> setAttr ".tan" 9;
> setAttr ".ktv[0]" 103 0;
> setAttr ".kot[0]" 5;
>
> would be what my regex would grab.
> I'm currently only able to grab out the first line and part of the
> second line, but no more.
> regex is as follows
>
> my_regexp = re.compile("createNode\ animCurve.*\n[\t*setAttr.*\n]*")
>
> I've run several variations of this, but none return me all of the
> expected information.
>
> Is there something special that needs to be done to have the regexp grab
> any number of the setAttr lines without specification?

Groups are marked with parens (...) not brackets [...].

>>> text = """\
.... createNode animCurveTU -n "test:master_globalSmooth";
.... setAttr ".tan" 9;
.... setAttr -s 4 ".ktv[0:3]" 101 0 163 0 169 0 201 0;
.... setAttr -s 4 ".kit[3]" 10;
.... setAttr -s 4 ".kot[3]" 10;
.... createNode animCurveTU -n "test:master_res";
.... setAttr ".tan" 9;
.... setAttr ".ktv[0]" 103 0;
.... setAttr ".kot[0]" 5;
.... createNode animCurveTU -n "test:master_faceRig";
.... setAttr ".tan" 9;
.... setAttr ".ktv[0]" 103 0;
.... setAttr ".kot[0]" 5;
.... """
>>> for m in re.compile("(createNode animCurve.*\n(\s*setAttr.*\n)*)").finditer(text):
.... print m.group(1)
.... print "-" * 40
....
createNode animCurveTU -n "test:master_globalSmooth";
setAttr ".tan" 9;
setAttr -s 4 ".ktv[0:3]" 101 0 163 0 169 0 201 0;
setAttr -s 4 ".kit[3]" 10;
setAttr -s 4 ".kot[3]" 10;

----------------------------------------
createNode animCurveTU -n "test:master_res";
setAttr ".tan" 9;
setAttr ".ktv[0]" 103 0;
setAttr ".kot[0]" 5;

----------------------------------------
createNode animCurveTU -n "test:master_faceRig";
setAttr ".tan" 9;
setAttr ".ktv[0]" 103 0;
setAttr ".kot[0]" 5;

----------------------------------------

Peter

 |  Next  |  Last
Pages: 1 2 3
Prev: An ODBC interface for Python 3?
Next: ANN: blist 1.2.0