473,385 Members | 1,830 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Making a tiny script language using python: I need a string processing lib

I do not know if there is any lib specially designed to process the
strings in scipt language.
for example:
I hope to process the string"print a,b,c,d,e "in the form"command
argumentlist" and return:
{'command'='print',
'argumentlist'=['a','b','c','d','e']}
Are there any lib to implement this?
Ideally , the lib should have a function like below:

def extract(commandstring, splitformat)

eg:
extract("see#you@tonight","what#whom@when")
return: {"what":"see","whom":"you","when":"tonight"}

extract("1;2;3;4;5","list[;]")
return: {"list":['1','2','3','4','5']}

extract("print a,b,c,d,e","command arglist[,]")
return: {"command":"print","arglist":['a','b','c','d','e']}

extract("fruit:apple~orgrange~pear~grape#name:tom; sam;dim;ham"
,"class1:instance1[~]#class2:instance2[;]")
return: {"class1":"fruit",
instance1:['apple','orange','pear','grape'],
"class2":"name",
"instance2":['tom','sam','dim','ham']
}

####### # # # #
# # # # #
# # # # #
# ####### #
# # # # #
# # # # #
# # # # #

Mar 3 '06 #1
4 1419
Sullivan WxPyQtKinter wrote:
I do not know if there is any lib specially designed to process the
strings in scipt language.
for example:
I hope to process the string"print a,b,c,d,e "in the form"command
argumentlist" and return:
{'command'='print',
'argumentlist'=['a','b','c','d','e']}
Are there any lib to implement this?
Ideally , the lib should have a function like below:

def extract(commandstring, splitformat)

eg:
extract("see#you@tonight","what#whom@when")
return: {"what":"see","whom":"you","when":"tonight"}

extract("1;2;3;4;5","list[;]")
return: {"list":['1','2','3','4','5']}

extract("print a,b,c,d,e","command arglist[,]")
return: {"command":"print","arglist":['a','b','c','d','e']}

extract("fruit:apple~orgrange~pear~grape#name:tom; sam;dim;ham"
,"class1:instance1[~]#class2:instance2[;]")
return: {"class1":"fruit",
instance1:['apple','orange','pear','grape'],
"class2":"name",
"instance2":['tom','sam','dim','ham']
}


Your best bets are simpleparse (http://simpleparse.sourceforge.net/) or
ply (http://www.dabeaz.com/ply/ply.html). Both have a little learning
curve but are well worth the time investment if you will be doing things
like you describe.

James
Mar 3 '06 #2
"Sullivan WxPyQtKinter" <su***********@gmail.com> wrote in message
news:11**********************@v46g2000cwv.googlegr oups.com...
I do not know if there is any lib specially designed to process the
strings in scipt language.
for example:
I hope to process the string"print a,b,c,d,e "in the form"command
argumentlist" and return:
{'command'='print',
'argumentlist'=['a','b','c','d','e']}
Are there any lib to implement this?
Ideally , the lib should have a function like below:

def extract(commandstring, splitformat)

eg:
extract("see#you@tonight","what#whom@when")
return: {"what":"see","whom":"you","when":"tonight"}

extract("1;2;3;4;5","list[;]")
return: {"list":['1','2','3','4','5']}

extract("print a,b,c,d,e","command arglist[,]")
return: {"command":"print","arglist":['a','b','c','d','e']}

extract("fruit:apple~orgrange~pear~grape#name:tom; sam;dim;ham"
,"class1:instance1[~]#class2:instance2[;]")
return: {"class1":"fruit",
instance1:['apple','orange','pear','grape'],
"class2":"name",
"instance2":['tom','sam','dim','ham']
}

####### # # # #
# # # # #
# # # # #
# ####### #
# # # # #
# # # # #
# # # # #

I gave two presentations at PyCon on using pyparsing, one was for a simple
adventure game that implemented a command parser. You can find the
presentations and sample code at
http://www.geocities.com/ptmcg/python/index.html.

-- Paul
Mar 3 '06 #3
On 2 Mar 2006 17:53:38 -0800, rumours say that "Sullivan WxPyQtKinter"
<su***********@gmail.com> might have written:
I do not know if there is any lib specially designed to process the
strings in scipt language.
for example:
I hope to process the string"print a,b,c,d,e "in the form"command
argumentlist" and return:
{'command'='print',
'argumentlist'=['a','b','c','d','e']}


Have you checked the shlex module in the standard library? It might be
useful.
--
TZOTZIOY, I speak England very best.
"Dear Paul,
please stop spamming us."
The Corinthians
Mar 4 '06 #4
I have gone over the shlex and cmd and so, but none of them are
satisfactory. However, I tried to program this this function on my own
and found it pretty easy.

Thank you so much for the suggestion, after all.

Mar 5 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

34
by: nobody | last post by:
This article is posted at the request of C.W. Yang who asked me to detail my opinion of Lisp, and for the benefit of people like him, who may find themselves intrigued by this language. The...
1
by: Kenneth McDonald | last post by:
I'm working on the 0.8 release of my 'rex' module, and would appreciate feedback, suggestions, and criticism as I work towards finalizing the API and feature sets. rex is a module intended to make...
7
by: Pankaj | last post by:
The module which i am creating is like Part A: 1. It does some processing by using python code. 2. The result of this python code execution is written to a text file. ] Part B: 1. I read a...
351
by: CBFalconer | last post by:
We often find hidden, and totally unnecessary, assumptions being made in code. The following leans heavily on one particular example, which happens to be in C. However similar things can (and...
23
by: Xah Lee | last post by:
The Concepts and Confusions of Pre-fix, In-fix, Post-fix and Fully Functional Notations Xah Lee, 2006-03-15 Let me summarize: The LISP notation, is a functional notation, and is not a...
0
by: gunimpi | last post by:
http://www.vbforums.com/showthread.php?p=2745431#post2745431 ******************************************************** VB6 OR VBA & Webbrowser DOM Tiny $50 Mini Project Programmer help wanted...
23
by: Python Maniac | last post by:
I am new to Python however I would like some feedback from those who know more about Python than I do at this time. def scrambleLine(line): s = '' for c in line: s += chr(ord(c) | 0x80)...
1
by: Xah Lee | last post by:
Text Processing with Emacs Lisp Xah Lee, 2007-10-29 This page gives a outline of how to use emacs lisp to do text processing, using a specific real-world problem as example. If you don't know...
11
by: Rafe | last post by:
Hi, I'm working within an application (making a lot of wrappers), but the application is not case sensitive. For example, Typing obj.name, obj.Name, or even object.naMe is all fine (as far as...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.