Re: Parsing files in python

Discussion in 'Python' started by Chris Angelico, Dec 24, 2012.

  1. 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
     
    Chris Angelico, Dec 24, 2012
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. GIMME
    Replies:
    2
    Views:
    917
    GIMME
    Feb 11, 2004
  2. Naren
    Replies:
    0
    Views:
    599
    Naren
    May 11, 2004
  3. Christopher Diggins
    Replies:
    0
    Views:
    624
    Christopher Diggins
    Jul 9, 2007
  4. Christopher Diggins
    Replies:
    0
    Views:
    453
    Christopher Diggins
    Jul 9, 2007
  5. John Levine
    Replies:
    0
    Views:
    756
    John Levine
    Feb 2, 2012
Loading...

Share This Page