How do I cut out a piece of text?

Mike Fletcher mfletch at tpresence.com
Thu Sep 14 13:47:35 EDT 2000


Another approach using mcf.vrml ...

>>> from mcf.vrml import loader
>>> sg = loader.load( 'p:\\temp\\test.wrl' )
monitor: Attempting to load file from p:\temp\test.wrl
monitor: Loading file p:\temp\test.wrl into memory
reached file end
monitor: File p:\temp\test.wrl loaded.
Load successful: <mcf.vrml.prototype2.sceneGraph instance at 2c687b0>
>>> sg.defNames["thigh01"]
<Transform('thigh01'): ['translation', 'children']>
>>> loader.save( sg.defNames["thigh01"], 'p:\\temp\\test2.wrl' )
monitor: Linearising sceneGraph to string
monitor: File saved to p:\temp\test2.wrl
Save successful: 6717
6717
>>> 

The advantage being that it explicitly manipulates the structures you're
dealing with, instead of mucking around with low-level string-slinging.  Of
course, it's much slower for these very simple tasks, but oh well, if the
task is simple you can use a text editor and get the job done :o) .  As a
side benefit, you'll get the "USE" expanded on linearisation so the
resulting file is usable (doesn't point to a non-existent DEF name). A major
disadvantage is that your files need to be valid VRML97 (won't load
otherwise).

Enjoy yourself,
Mike

-----Original Message-----
From: Opinderjit [mailto:bhellao at my-deja.com]
Sent: Thursday, September 14, 2000 1:05 PM
To: python-list at python.org
Subject: Re: How do I cut out a piece of text?
...
import re
re.search(r"(?P<faceB>\s+DEF\s+faceB\s+.*(?=DEF\s+faceC)", VRML, re.S)
print b.group("faceB")
...
In article <8pq0kg$d20$1 at nyheter.chalmers.se>,
  "Fredrik Lundin" <m94lufr at mtek.chalmers.se> wrote:
> Hey!
>
> I want to cut out a piece of text and put it in a new file.
> Lets say that the text looks like this (VRML transform nodes):
...
> Could someone help me with this?
> I have tried quite alot to accomplish it, but I can't seem to
eliminate the
> stuff ahead of the wanted text portion.
...




More information about the Python-list mailing list