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

perl to python

Hello ,

What is the python way of doing this :
perl -pi -e 's/string1/string2/' file
?
Thanks
Olivier
Jul 18 '05
52 3688
On 2004-05-12, Aahz <aa**@pythoncraft.com> wrote:
In article <sl******************@eyegor.jobsluder.net>,
Kirk Job-Sluder <ki**@eyegor.jobsluder.net> wrote:

And here is the fundamental question. Why should I spend my time
writing a module in python to emulate another tool, when I can simply
use that other tool? Why should I, as a resarcher who must process
large quantities of data, spend my time and my employer's money
reinventing the wheel?


Why should your employer pay for the time for all of its employees to
learn all of those other tools, when Python will do the job?


As was brought up earlier. Creating custom python scripts to reinvent
the wheel is also loaded with training costs. I would argue the
following:

1: Using an existing idiomatic tool takes advantage of standardization.
"perl -pi -e" exhibits the same behavior on multiple platforms and even
different versions of perl. It is an idiomatic expression that is very
well documented, and for which 100s of examples through a quick google
search.

2: Memorizing two lines is more difficult than memorizing one line.

3: The alternative proposal, writing a site-specific module is even
worse when it comes to training requirements.

Or to turn this around, why should anybody learn to use tar, find, less,
rsync or diff when you can do the same thing in python?

Jul 18 '05 #51
It's in the python man page:

-u Force stdin, stdout and stderr to be totally unbuffered.
On systems where it matters, also put stdin, stdout and stderr in binary
mode. Note that there is internal buffering in xread-lines(),
readlines() and file-object iterators ("for line in sys.stdin") which
is not influenced by this option. To work around this, you will want to
use "sys.stdin.readline()" inside a "while 1:" loop.

When I use sys.stdin.readline I don't need to use to -u flag.

You can also use raw_input() to get data from stdin. This also appears to
strip out the newline.
Josh Gilbert.

Andrew Dalke wrote:
Scott Schwartz
No effect, because that's not the problem.


Ahh, you're right. I keyword matched "buffer" and thought you meant
the system buffer and not Python's.

Andrew
da***@dalkescientific.com


Jul 18 '05 #52
On Tue, 11 May 2004 14:45:59 +0100, Peter Hickman
<pe***@semantico.com> wrote:
There is more to computer usage than sysadmin tasks, sed is an ideal
tool for processing large sets of large files (I have to handle small
files that are only 130 Mb in size, and I have around 140,000 of them).


Out of curiosity, what are you doing that generates 140,000 files of
130 megabytes each?

--
"Sore wa himitsu desu."
To reply by email, remove
the small snack from address.
Jul 18 '05 #53

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

Similar topics

9
by: Roy Smith | last post by:
I'm working on a prototype of a new application in Python. At some point, if this ever turns into a product, the powers that be will almost certainly demand that it be done in Perl. My job will...
42
by: Fred Ma | last post by:
Hello, This is not a troll posting, and I've refrained from asking because I've seen similar threads get all nitter-nattery. But I really want to make a decision on how best to invest my time....
46
by: Reinhold Birkenfeld | last post by:
Hello, another Perl/Python question: the subject says it all. Perl is going to change dramatically to become a more powerful and easier to (read|write) language. Is Python taking a similar...
17
by: Michael McGarry | last post by:
Hi, I am just starting to use Python. Does Python have all the regular expression features of Perl? Is Python missing any features available in Perl? Thanks, Michael
31
by: surfunbear | last post by:
I've read some posts on Perl versus Python and studied a bit of my Python book. I'm a software engineer, familiar with C++ objected oriented development, but have been using Perl because it is...
9
by: Dieter Vanderelst | last post by:
Dear all, I'm currently comparing Python versus Perl to use in a project that involved a lot of text processing. I'm trying to determine what the most efficient language would be for our...
20
by: Xah Lee | last post by:
Sort a List Xah Lee, 200510 In this page, we show how to sort a list in Python & Perl and also discuss some math of sort. To sort a list in Python, use the “sort” method. For example: ...
13
by: squash | last post by:
I am a little annoyed at why such a simple program in Perl is causing so much difficulty for python, i.e: $a += 200000 * 140000; print $a;
12
by: rurpy | last post by:
Is there an effcient way (more so than cgi) of using Python with Microsoft IIS? Something equivalent to Perl-ISAPI?
8
by: Palindrom | last post by:
Hi everyone ! I'd like to apologize in advance for my bad english, it's not my mother tongue... My girlfriend (who is a newbie in Python, but knows Perl quite well) asked me this morning why...
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:
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
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.