Re: Is there a Python equivalent to Perl's File::Listing::parse_dir

2010-09-02 Thread Stefan Schwarzer
Hi John, On 2010-08-11 20:24, John Nagle wrote: Perl has a function which will take a remote directory page, in the form that most web sites return for a file directory, and parse it into a useful form: http://www.xav.com/perl/site/lib/File/Listing.html This is especially useful

Is there a Python equivalent to Perl's File::Listing::parse_dir

2010-08-11 Thread John Nagle
Perl has a function which will take a remote directory page, in the form that most web sites return for a file directory, and parse it into a useful form: http://www.xav.com/perl/site/lib/File/Listing.html This is especially useful for FTP sites. Is there a Python equivalent of this?

Re: Is there a Python equivalent to Perl's File::Listing::parse_dir

2010-08-11 Thread Thomas Jollans
On Wednesday 11 August 2010, it occurred to John Nagle to exclaim: This is especially useful for FTP sites. It sounds like you're trying to use HTTP to something a lot more easily done with FTP, without any reason not to use FTP. http://docs.python.org/library/ftplib.html#ftplib.FTP.dir --

python equivalent to perl's inplace edit mechanism

2008-05-08 Thread Michael Mabin
Does python have an equivalent to Perl's inplace-edit variable $^I? For example, the following perl code below changes mike to dave in a file that is passed as an argument. #!/usr/bin/env perl #chgit script $^I = ''; while() { s/mike/dave/g; print; } The script would be used as below: chgit

Re: python equivalent to perl's inplace edit mechanism

2008-05-08 Thread David
#!/usr/bin/env perl #chgit script $^I = ''; while() { s/mike/dave/g; print; } #!/usr/bin/python import sys lines = open(sys.argv[1]).readlines() open(sys.argv[1], 'w').writelines([line.replace('mike', 'dave') for line in lines]) -- http://mail.python.org/mailman/listinfo/python-list

Re: python equivalent to perl's inplace edit mechanism

2008-05-08 Thread Gabriel Genellina
En Thu, 08 May 2008 09:11:56 -0300, Michael Mabin [EMAIL PROTECTED] escribió: Does python have an equivalent to Perl's inplace-edit variable $^I? For example, the following perl code below changes mike to dave in a file that is passed as an argument. #!/usr/bin/env perl #chgit script $^I =

Re: python equivalent to perl's inplace edit mechanism

2008-05-08 Thread David
On Thu, May 8, 2008 at 2:11 PM, Michael Mabin [EMAIL PROTECTED] wrote: Does python have an equivalent to Perl's inplace-edit variable $^I? I misread your question. No, Python eschews magic characters and symbols. They make code ugly and harder to read and maintain. The first 3 lines of the

Re: python equivalent to perl's inplace edit mechanism

2008-05-08 Thread Michael Mabin
I miswrote my question. But I still completely understand. What I really wanted to know was whether there was something equivalent to how perl can perform inplace edits of a file with something like the magic $^I variable. I see from Gabriel that you can use the fileinput module to achieve

Python equivalent of Perl's $/

2007-08-20 Thread John K Masters
I am currently working my way through Jeffrey Friedl's book Mastering Regular Expressions. Great book apart from the fact it uses Perl for the examples. One particular expression that interests me is '$/ = .\n' which, rather than splitting a file into lines, splits on a period-newline boundary.

Re: Python equivalent of Perl's $/

2007-08-20 Thread kyosohma
On Aug 19, 1:13 pm, John K Masters [EMAIL PROTECTED] wrote: I am currently working my way through Jeffrey Friedl's book Mastering Regular Expressions. Great book apart from the fact it uses Perl for the examples. One particular expression that interests me is '$/ = .\n' which, rather than

Re: Python equivalent of Perl's $/

2007-08-20 Thread Mark T
John K Masters [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] I am currently working my way through Jeffrey Friedl's book Mastering Regular Expressions. Great book apart from the fact it uses Perl for the examples. One particular expression that interests me is '$/ = .\n' which,

Re: Python equivalent of Perl's $/

2007-08-20 Thread Nick Craig-Wood
John K Masters [EMAIL PROTECTED] wrote: I am currently working my way through Jeffrey Friedl's book Mastering Regular Expressions. Great book apart from the fact it uses Perl for the examples. One particular expression that interests me is '$/ = .\n' which, rather than splitting a file

Re: Python equivalent of Perl's $/

2007-08-20 Thread John K Masters
On 10:30 Mon 20 Aug , Nick Craig-Wood wrote: Something like this maybe? import re input_data = I am currently working my way through Jeffrey Friedl's book Mastering Regular Expressions. Great book apart from the fact it uses Perl for the examples. One particular expression that

Re: Python equivalent of Perl's $/

2007-08-20 Thread [EMAIL PROTECTED]
On Aug 19, 11:13 am, John K Masters [EMAIL PROTECTED] wrote: I am currently working my way through Jeffrey Friedl's book Mastering Regular Expressions. Great book apart from the fact it uses Perl for the examples. One particular expression that interests me is '$/ = .\n' which, rather than

Re: Python equivalent of Perl's $/

2007-08-20 Thread John K Masters
On 19:19 Mon 20 Aug , [EMAIL PROTECTED] wrote: import StringIO text = \ To mimic Perl's input record separator in Python, you can use a generator. And a substring test. Perhaps something like the following is what you wanted. mockfile = StringIO.StringIO(text) def

Re: Python equivalent of Perl's $/

2007-08-20 Thread [EMAIL PROTECTED]
On Aug 20, 1:02 pm, John K Masters [EMAIL PROTECTED] wrote: On 19:19 Mon 20 Aug , [EMAIL PROTECTED] wrote: import StringIO text = \ To mimic Perl's input record separator in Python, you can use a generator. And a substring test. Perhaps something like the following is what