Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9043191
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T10:41:12+00:00 2026-06-16T10:41:12+00:00

I have the following lisp file, which is from the UCI machine learning database

  • 0

I have the following lisp file, which is from the UCI machine learning database. I would like to convert it into a flat text file using python. A typical line looks like this:

(1 ((st 8) (pitch 67) (dur 4) (keysig 1) (timesig 12) (fermata 0))((st 12) (pitch 67) (dur 8) (keysig 1) (timesig 12) (fermata 0)))

I would like to parse this into a text file like:

time pitch duration keysig timesig fermata
8    67    4        1      12      0
12   67    8        1      12      0

Is there a python module to intelligently parse this? This is my first time seeing lisp.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T10:41:13+00:00Added an answer on June 16, 2026 at 10:41 am

    As shown in this answer, pyparsing appears to be the right tool for that:

    inputdata = '(1 ((st 8) (pitch 67) (dur 4) (keysig 1) (timesig 12) (fermata 0))((st 12) (pitch 67) (dur 8) (keysig 1) (timesig 12) (fermata 0)))'
    
    from pyparsing import OneOrMore, nestedExpr
    
    data = OneOrMore(nestedExpr()).parseString(inputdata)
    print data
    
    # [['1', [['st', '8'], ['pitch', '67'], ['dur', '4'], ['keysig', '1'], ['timesig', '12'], ['fermata', '0']], [['st', '12'], ['pitch', '67'], ['dur', '8'], ['keysig', '1'], ['timesig', '12'], ['fermata', '0']]]]
    

    For the completeness’ sake, this is how to format the results (using texttable):

    from texttable import Texttable
    
    tab = Texttable()
    for row in data.asList()[0][1:]:
        row = dict(row)
        tab.header(row.keys())
        tab.add_row(row.values())
    print tab.draw()
    
    +---------+--------+----+-------+-----+---------+
    | timesig | keysig | st | pitch | dur | fermata |
    +=========+========+====+=======+=====+=========+
    | 12      | 1      | 8  | 67    | 4   | 0       |
    +---------+--------+----+-------+-----+---------+
    | 12      | 1      | 12 | 67    | 8   | 0       |
    +---------+--------+----+-------+-----+---------+
    

    To convert that data back to the lisp notation:

    def lisp(x):
        return '(%s)' % ' '.join(lisp(y) for y in x) if isinstance(x, list) else x
    
    d = lisp(d[0])
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Lisp (SBCL 1.0.40.0.debian) application (myfitnessdata), which uses the following code to
I have an Emacs command like following: (defun query-lisp (word) (interactive sType a word
I have the following code in my .emacs file, which works as you'd expect:
I have following SQL statementL: select DATE(bla), count(*) from tableA group by DATE(bla) UNION
I have the following Common Lisp code: (defun micro-read-eval-print () (format t Micro >
I have been searching everywhere for the following functionality in Lisp, and have gotten
In Lisp, I have to create a program that does the following (please visit
I have an Emacs Lisp file with custom macros I want fontified and indented
I have the following from the slime repl (no clojure.contib functions found): M-X slime
I have the following Common Lisp function: (defun get-positions (marker) (let ((result nil)) (dotimes

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.