473,396 Members | 1,805 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,396 software developers and data experts.

python line editor

Art
Hello all,

this is possibly a not well-formed question, but are there any python
modules out there to do vi/ex/ed style script editing?

i.e. the kind where you pass the commands thru stdin. ie:
/sFoo
:i"Bar"
:wq

or something like that.

I'm porting some software right now so I have thousands of files to do
replaces on. I want to do everything in Python, but I find myself
writing a bunch of functions that look like this:
for line in fileinput.input( os.path.join( dir,
file ), inplace=1, backup="~"):
m = xbrex.match( line )
if m:
resdef = ""
#is this an ndef?
if m.group(1):
resdef = "#if !defined(_XBOX) &&
!defined(_PS2)"
else:
resdef = "#if defined(_XBOX) ||
defined(_PS2)"
#fixup the line
line = line.replace(m.group(0), resdef)

# write the line
sys.stdout.write(line)

Basically my problem is that I have to operate on files on a line by
line basis using this method. This case works fine, but there are
cases where I would like multi-line changes, basically mini-editor
support.

I know that this could be done with code i.e. if( startFound ): ...,
but I don't want to have to track a bunch of flags. . .

I know I could slurp the whole file into a string, but that still
doesn't have the simplicity of the ed syntax.

Since I'm basically asking for editor functionality, an alternative
would be to do this with ed and scripts, or elisp, but I'd like to try
python for this first.

Any suggestions?

Best regards,
Aaron
Jul 18 '05 #1
1 1554
I'm having a hard time understanding your question,

what exactly would
/sFoo
:i"Bar"
:wq

do to a file, do you have a GUI available?

Have a look at sys.argv() and glob.glob() in the standard libraries they
might help.

Tom
Jul 18 '05 #2

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

Similar topics

699
by: mike420 | last post by:
I think everyone who used Python will agree that its syntax is the best thing going for it. It is very readable and easy for everyone to learn. But, Python does not a have very good macro...
145
by: David MacQuigg | last post by:
Playing with Prothon today, I am fascinated by the idea of eliminating classes in Python. I'm trying to figure out what fundamental benefit there is to having classes. Is all this complexity...
852
by: Mark Tarver | last post by:
How do you compare Python to Lisp? What specific advantages do you think that one has over the other? Note I'm not a Python person and I have no axes to grind here. This is just a question for...
9
by: korean_dave | last post by:
From command Prompt, i type in a script, "tryme.py". This, instead, brings up PythonWin editor and Interactive Window. Path variable is "C:\Python24". (I need Python 2.4 installed, not 2.5) ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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?
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.