Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Re: Parsing files in python

Reply
Thread Tools

Re: Parsing files in python

 
 
Chris Angelico
Guest
Posts: n/a
 
      12-24-2012
On Mon, Dec 24, 2012 at 4:19 AM, Kene Meniru <> wrote:
> Hello: I am writing a program that is made up of a collection of POV-Ray macros. POV-Ray is available at povray.org. It is a ray-tracing program that reads a scene description language (SDL) to create photo-realistic images.. At this time my program (for modeling building information) is so huge that I am finding it difficult managing the macros and I am not even near completion.


I love POV-Ray! Great software, but the input language does at times
lack something, so I'm not surprised that you're wanting a pre-parser.

> ------------possible user file content for parsing ------------
> // in the following the python interface program reads
> //+ the contents of the file "other.file" as if its content
> //+ were located at this point.
> include other.file
>
> //In the following the python interface makes "snap_size" a
> //+ global parameter
> declare snap_size = 10
>
>
> // In the following "buildingLevel" is a class that is
> //+ called and passed the parameters in parenthesis.
> buildingLevel("FirstLevel", 3000)
>
> // In the following "snapOffset" is a class that is
> //+ called and passed the parameters in parenthesis.
> snapOffset("Closet-S1_r1", "Closet-S2_r3", <0,0,0>)
> ------------end of user file content
>
> It should also be possible to include comments using double-slashes, etc.


Hmm. That's a fairly complex file format you have there. I wonder if
it'd be possible to use an actual language parser for it - for
instance, to make this a real Python program. You'd have to use # for
a comment rather than //, and vector syntax may be a problem, but for
the rest, you should be able to do it all with just one extra line at
the top:

from povray_macros import *

You then write all your macros in a file called povray_macros.py and
they'll be conveniently available. For instance:

def buildingLevel(name, altitude):
print("... whatever POV-Ray code is needed ...")

Unfortunately POV-Ray doesn't seem to support reading from stdin, so
you can't simply pipe your program into the renderer. But you can do
it this way:

my_file_whatever_it_is.py >temp.pov
povray +Itemp.pov

ChrisA
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
What libraries should I use for MIME parsing, XML parsing, and MySQL ? John Levine Ruby 0 02-02-2012 11:15 PM
[ANN] Parsing Tutorial and YARD 1.0: A C++ Parsing Framework Christopher Diggins C++ 0 07-09-2007 09:01 PM
[ANN] Parsing Tutorial and YARD 1.0: A C++ Parsing Framework Christopher Diggins C++ 0 07-09-2007 08:58 PM
SAX Parsing - Weird results when parsing content between tags. Naren XML 0 05-11-2004 07:25 PM
Perl expression for parsing CSV (ignoring parsing commas when in double quotes) GIMME Perl 2 02-11-2004 05:40 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57