On Mon, Nov 12, 2018 at 11:20 PM Anssi Saari wrote:
>
> Chris Angelico writes:
>
> > On Fri, Nov 9, 2018 at 11:11 PM Anssi Saari wrote:
> >>
> >> Chris Angelico writes:
> >>
> >> > No helper needed. Safe against command injection. Uses the known
> >> > format of the command's output; if you wan
Chris Angelico writes:
> On Fri, Nov 9, 2018 at 11:11 PM Anssi Saari wrote:
>>
>> Chris Angelico writes:
>>
>> > No helper needed. Safe against command injection. Uses the known
>> > format of the command's output; if you want other information as well
>> > as the type, you could get that too.
srinivasan wrote:
> Even after changing as per the below
> "blkid -o export %s | grep 'TYPE' | cut -d'=' -f3"
> or:
> 'blkid -o export %s | grep "TYPE" | cut -d"=" -f3'
> or:
> "blkid -o export %s | grep \&quo
On Fri, Nov 9, 2018 at 11:11 PM Anssi Saari wrote:
>
> Chris Angelico writes:
>
> > No helper needed. Safe against command injection. Uses the known
> > format of the command's output; if you want other information as well
> > as the type, you could get that too.
>
> Can someone let me in on this
Chris Angelico writes:
> No helper needed. Safe against command injection. Uses the known
> format of the command's output; if you want other information as well
> as the type, you could get that too.
Can someone let me in on this secret helper module? Doesn't seem to
match the helper module in
I feel I have kick started my learning in python :)
Have a great day ahead!
On Wed, Nov 7, 2018 at 3:11 PM Ben Bacarisse wrote:
> srinivasan writes:
>
> > Even after changing as per the below
> > "blkid -o export %s | grep 'TYPE' | cut -d'=' -f3"
&
srinivasan writes:
> Even after changing as per the below
> "blkid -o export %s | grep 'TYPE' | cut -d'=' -f3"
> or:
> 'blkid -o export %s | grep "TYPE" | cut -d"=" -f3'
> or:
> "blkid -o export %s | grep \&qu
On Wed, Nov 7, 2018 at 11:42 PM srinivasan wrote:
>
> Some I managed to fix temporarily as below, might be useful for others. Also
> please correct me if anything wrong or for any improvements in the below
>
> cmd = "blkid -o export %s" % partition_path
> out = self._helper.execut
nivasan wrote:
> > > Even after changing as per the below
> > > "blkid -o export %s | grep 'TYPE' | cut -d'=' -f3"
> > > or:
> > > 'blkid -o export %s | grep "TYPE" | cut -d"=" -f3'
> > > or:
> >
On Wed, Nov 7, 2018 at 11:36 PM Qian Cai wrote:
>
> srinivasan wrote:
> > Even after changing as per the below
> > "blkid -o export %s | grep 'TYPE' | cut -d'=' -f3"
> > or:
> > 'blkid -o export %s | grep "TYPE" | cut -
srinivasan wrote:
> Even after changing as per the below
> "blkid -o export %s | grep 'TYPE' | cut -d'=' -f3"
> or:
> 'blkid -o export %s | grep "TYPE" | cut -d"=" -f3'
> or:
> "blkid -o export %s | grep \&quo
Even after changing as per the below
"blkid -o export %s | grep 'TYPE' | cut -d'=' -f3"
or:
'blkid -o export %s | grep "TYPE" | cut -d"=" -f3'
or:
"blkid -o export %s | grep \"TYPE\" | cut -d\"=\" -f3"
S
On Wed, 2018-11-07 at 10:22 +0100, srinivasan wrote:
> blkid -o export %s | grep \'TYPE\' | cut -d\"=\" -f3
You don't need to escape the single quotes.
Try either:
"blkid -o export %s | grep 'TYPE' | cut -d'=' -f3"
or:
'blkid -o e
After changing the line to *"cmd = "blkid -o export %s | grep \'TYPE\' |
cut -d\"=\" -f3" % fs"*, Now I dont see the error "SyntaxError: can't
assign to literal"
This is not returning exactly "*vfat*" instead of this, it is return
On 06/11/2018 18:10, srinivasan wrote:
root:~/qa/test_library# python3 sd.py
File "sd.py", line 99
*cmd = "blkid -o export %s | grep 'TYPE' | cut -d"=" -f3" % (fs)*
* ^*
*SyntaxError: can't assign to literal*
Look at the 'c
:return: filesystem type as string or None if not found
"""
*cmd = "blkid -o export %s | grep 'TYPE' | cut -d"=" -f3" % (fs)*
*return self._helper.execute_cmd_output_string(cmd)*
*def execute_cmd_output_string(sel
Iranna Mathapati writes:
> How to grep values from below out put string.
>
> pattern should include "Fabric Module".
One possible way would be to use a regular expression --
see the documentation for the "re" module.
--
https://mail.python.org/mailman/listinfo/python-list
On Fri, 4 Aug 2017 10:33 pm, Iranna Mathapati wrote:
> Hi Team,
>
> How to grep values from below out put string.
>
> pattern should include "Fabric Module".
>
> grepping Fabric module values only
>
> str = '''
> 22 0Fabric Modul
Hi Team,
How to grep values from below out put string.
pattern should include "Fabric Module".
grepping Fabric module values only
str = '''
22 0Fabric Module J8N-C9508-FM ok
24 0Fabric ModuleJ8N-C95
On 03/01/2017 02:55 PM, rob...@forzasilicon.com wrote:
> Obviously, not what I want. Can anyone feed some input?
You've already got some good answers, but I just wanted to point you at
this good resource:
http://www.dabeaz.com/generators/
Pretty much anything you do in a shell script that involv
pt uses an external call to grep via subprocess, but I would like to
internalize everything to run in Python. I've read that re can accomplish the
filtering, but I am having trouble getting it to duplicate what I already
have.
# USING EXTERNAL GREP #
# display RAID controller inf
Thanks, Chris. That was nice and easy and very simple.
--
https://mail.python.org/mailman/listinfo/python-list
pt in cron. The
> script uses an external call to grep via subprocess, but I would like to
> internalize everything to run in Python. I've read that re can accomplish the
> filtering, but I am having trouble getting it to duplicate what I already
> have.
>
> p = subprocess.Pop
Hi All,
I'm relatively new to Python, and I am having some trouble with one of my
scripts. Basically, this script connects to a server via ssh, runs Dell's
omreport output, and then externally pipes it to a mail script in cron. The
script uses an external call to grep via subproc
On 11/06/2015 05:25 AM, William Ray Wing wrote:
On Nov 5, 2015, at 10:36 PM, Larry Hudson via Python-list
wrote:
[snip]
You’re not REALLY an old timer unless you’ve used TECO.
-Bill
Agreed. I'm not really and old-timer, just old (I'm 78).
My first exposure to computers was the MITS Al
> On Nov 5, 2015, at 10:36 PM, Larry Hudson via Python-list
> wrote:
>
> On 11/05/2015 05:18 PM, Dennis Lee Bieber wrote:
>> On Thu, 5 Nov 2015 20:19:39 + (UTC), Grant Edwards
>> declaimed the following:
>>
>>> Though I used a line-editor for a while on VMS, I was never very good
>>> at i
On 2015-11-06, Dennis Lee Bieber wrote:
> On Thu, 5 Nov 2015 20:19:39 + (UTC), Grant Edwards
> declaimed the following:
>
>>Though I used a line-editor for a while on VMS, I was never very good
>>at it, and abanded it for a full-screen editor at he first
>>opportunity. But, if you ever get a
On Thu, 05 Nov 2015 19:36:11 -0800, Larry Hudson wrote:
> Anyone besides me remember the CP/M editor Mince (Mince Is Not
> Complete EMACS)? It was an emacs-like editor, without any e-Lisp or
> other way of extending it. I believe it was my first exposure to a
> screen-oriented editor. I quite l
On 11/05/2015 05:18 PM, Dennis Lee Bieber wrote:
On Thu, 5 Nov 2015 20:19:39 + (UTC), Grant Edwards
declaimed the following:
Though I used a line-editor for a while on VMS, I was never very good
at it, and abanded it for a full-screen editor at he first
opportunity. But, if you ever get a
On 2015-11-05, Random832 wrote:
> Grant Edwards writes:
>> On 2015-11-05, Random832 wrote:
>>> Of course, both of those things are also true of ed.
>>
>> Well, maybe not for you. I knew people who (yonks ago) used 'ed' for
>> regular file editing. And I remember using the VMS line-editor for
>
Grant Edwards writes:
> On 2015-11-05, Random832 wrote:
>> Of course, both of those things are also true of ed.
>
> Well, maybe not for you. I knew people who (yonks ago) used 'ed' for
> regular file editing. And I remember using the VMS line-editor for
> regular file editing for a couple years
On 2015-11-05, Random832 wrote:
> Chris Angelico writes:
>> As someone who grew up on MS-DOS, I'd like to mention that EDLIN's
>> value wasn't in the obvious places. There were two features it had
>> that most other editors didn't: firstly, it would read only as much
>> of the file as it needed,
Chris Angelico writes:
> As someone who grew up on MS-DOS, I'd like to mention that EDLIN's
> value wasn't in the obvious places. There were two features it had
> that most other editors didn't: firstly, it would read only as much of
> the file as it needed, so you could edit a file larger than av
On Thu, Nov 5, 2015 at 6:32 PM, Christian Gollwitzer wrote:
> The point I'm so amused is, that MS has not felt the need to ship a real
> editor, and also cut back on most of the other tools that make computing,
> even on commandlines, a pleasant experience. Readline? Tab-Completion? I
> read a mag
Am 05.11.15 um 01:42 schrieb Chris Angelico:
On Thu, Nov 5, 2015 at 6:38 AM, Christian Gollwitzer wrote:
As someone who grew up on MS-DOS, I'd like to mention that EDLIN's
value wasn't in the obvious places. There were two features it had
that most other editors didn't: firstly, it would read on
On Thu, Nov 5, 2015 at 6:38 AM, Christian Gollwitzer wrote:
> Am 04.11.15 um 19:24 schrieb Ben Finney:
>>
>> The name is a mnemonic for a compound command in ‘ed’ [0], a text editor
>> that pre-dates extravagant luxuries like “presenting a full screen of
>> text at one time”.
>>
>> [... lots of f
Am 04.11.15 um 19:24 schrieb Ben Finney:
The name is a mnemonic for a compound command in ‘ed’ [0], a text editor
that pre-dates extravagant luxuries like “presenting a full screen of
text at one time”.
[... lots of fun facts ...]
Here is another fun fact: The convincing UI of ed was actually
On 2015-11-05 05:24, Ben Finney wrote:
> A very common command to issue, then, is “actually show me the line
> of text I just specified”; the ‘p’ (for “print”) command.
>
> Another very common command is “find the text matching this pattern
> and perform these commands on it”, which is ‘g’ (for “g
Steven D'Aprano writes:
> On Wednesday 04 November 2015 13:55, Dan Sommers wrote:
>
> > Its very name indicates that its default mode most certainly is
> > regular expressions.
>
> I don't even know what grep stands for.
“grep” stands for ‘g/RE/p’.
The
On Sat, Nov 23, 2013 at 5:29 PM, Peter Otten <__pete...@web.de> wrote:
> Luca wrote:
>
>> I'm trying to use sh (https://pypi.python.org/pypi/sh) for calling
>> system grep command but it's now working as expected.
>>
>> An example:
>>
>
Luca wrote:
> I'm trying to use sh (https://pypi.python.org/pypi/sh) for calling
> system grep command but it's now working as expected.
>
> An example:
>
> import sh
> sh.grep('abc', os.getcwd(), '-r')
>
> But I get the ErrorRet
In article ,
Luca wrote:
> I'm trying to use sh (https://pypi.python.org/pypi/sh) for calling
> system grep command but it's now working as expected.
>
> An example:
>
> import sh
> sh.grep('abc', os.getcwd(), '-r')
>
> But
I'm trying to use sh (https://pypi.python.org/pypi/sh) for calling
system grep command but it's now working as expected.
An example:
import sh
sh.grep('abc', os.getcwd(), '-r')
But I get the ErrorReturnCode_1: exception, that I learned is the
normal exit
On Feb 11, 2:06 am, Alexander Gattin wrote:
> Hello,
>
> On Tue, Feb 08, 2011 at 05:32:05PM +, Icarus
>
> Sparry wrote:
> > The key thing which makes this 'modern' is the
> > '+' at the end of the command, rather than '\;'.
> > T
Hello,
On Tue, Feb 08, 2011 at 05:32:05PM +, Icarus
Sparry wrote:
> The key thing which makes this 'modern' is the
> '+' at the end of the command, rather than '\;'.
> This causes find to execute the grep once per
> group of files, rather than onc
Hello,
On Thu, Feb 10, 2011 at 07:52:34AM +0100, Petter
Gustad wrote:
> r...@rpw3.org (Rob Warnock) writes:
> > invocation was given only one arg!! IT FOUND
> > THE PATTERN, BUT DIDN'T TELL ME WHAT
> > !@^%!$@#@! FILE IT WAS IN!! :-{
>
> Sounds frustrating, but
r...@rpw3.org (Rob Warnock) writes:
> invocation was given only one arg!! IT FOUND THE PATTERN, BUT DIDN'T
> TELL ME WHAT !@^%!$@#@! FILE IT WAS IN!! :-{
Sounds frustrating, but grep -H will always print the filename, even
when given a single filename on the command line.
//Pett
At 09:39 PM 2/9/2011, Rob Warnock wrote:
Harald Hanche-Olsen wrote:
[snip]
Years & years ago, right after I learned about "xargs", I got burned
several times on "find | xargs grep pat" when the file list was long
enough that "xargs" fired up more than one
Harald Hanche-Olsen wrote:
+---
| [Icarus Sparry ]
| > The 'modern' way to do this is
| > find . -maxdepth 2 -name '*.html' -exec grep whatever {} +
|
| Actually, I think it should be
| find . -maxdepth 2 -name '*.html' -exec grep whatever /dev
Harald Hanche-Olsen wrote:
+---
| [Icarus Sparry ]
| > The 'modern' way to do this is
| > find . -maxdepth 2 -name '*.html' -exec grep whatever {} +
|
| Actually, I think it should be
| find . -maxdepth 2 -name '*.html' -exec grep whatever /
Xah Lee writes:
>> You can rely on shell globbing, so that grep gets a list of all files in
>> all subdirectories. For example, I can grep all header files of the
>> linux kernel using
>>
>> % grep FOO /usr/src/linux/**/*.h
>
> say, i want to search in th
[Icarus Sparry ]
> The 'modern' way to do this is
> find . -maxdepth 2 -name '*.html' -exec grep whatever {} +
Actually, I think it should be
find . -maxdepth 2 -name '*.html' -exec grep whatever /dev/null {} + \;
because grep behaves differently when g
[Icarus Sparry ]
> The 'modern' way to do this is
> find . -maxdepth 2 -name '*.html' -exec grep whatever {} +
Actually, I think it should be
find . -maxdepth 2 -name '*.html' -exec grep whatever /dev/null {} +
because grep behaves differently when given onl
On Tue, 08 Feb 2011 14:30:53 -0800, Xah Lee wrote:
> On Feb 8, 9:32 am, Icarus Sparry wrote:
[snip]
>> The 'modern' way to do this is
>> find . -maxdepth 2 -name '*.html' -exec grep whatever {} +
>>
>> The key thing which makes this 'modern
On Feb 8, 9:32 am, Icarus Sparry wrote:
> On Tue, 08 Feb 2011 13:51:54 +0100, Petter Gustad wrote:
> > Xah Lee writes:
>
> >> problem with find xargs is that they spawn grep for each file, which
> >> becomes too slow to be usable.
>
> > find . -maxdepth
Icarus Sparry writes:
> The 'modern' way to do this is
> find . -maxdepth 2 -name '*.html' -exec grep whatever {} +
Agree, I've noticed that recent version of find have the + option. I
remember in the old days the exec method was considered bad since it
would fork
On Tue, 08 Feb 2011 13:51:54 +0100, Petter Gustad wrote:
> Xah Lee writes:
>
>> problem with find xargs is that they spawn grep for each file, which
>> becomes too slow to be usable.
>
> find . -maxdepth 2 -name '*.html -print0 | xargs -0 grep whatever
>
Xah Lee writes:
> problem with find xargs is that they spawn grep for each file, which
> becomes too slow to be usable.
find . -maxdepth 2 -name '*.html -print0 | xargs -0 grep whatever
will call grep with a list of filenames given by find, only a single
grep process will run.
On Thu, 10 Jun 2010 08:40:03 -0700, Chris Seberino wrote:
> On Jun 10, 6:52 am, Nobody wrote:
>> Without the p1.stdout.close(), if the reader (grep) terminates before
>> consuming all of its input, the writer (ls) won't terminate so long as
>> Python retains the desc
On 6/10/2010 11:40 AM, Chris Seberino wrote:
Even if zombies are created, they will eventually get dealt with my OS
w/o any user intervention needed right?
Bad approach. Years ago I inherited a server that didn't do a proper cleanup pf
its slaves. After a few days running, people discovered t
On Jun 10, 7:56 am, "D'Arcy J.M. Cain" wrote:
> On Thu, 10 Jun 2010 08:26:58 +0100
> I'm surprised that there is anyone left who hasn't killfiled this guy.
> He/she hasn't made any effort to understand the group. Why bother even
> answering him? Just filter him and enjoy the silence.
All this
On Thu, Jun 10, 2010 at 4:52 AM, Nobody wrote:
>
> Also, "ls | grep" may provide a useful tutorial for the subprocess module,
> but if you actually need to enumerate files, use e.g. os.listdir/os.walk()
> and re.search/fnmatch, or glob. Spawning child processes to perform ta
On 06/10/10 21:52, Nobody wrote:
> Spawning child processes to perform tasks
> which can easily be performed in Python is inefficient
Not necessarily so, recently I wrote a script which takes a blink of an
eye when I pipe through cat/grep to prefilter the lines before doing
further c
On Jun 10, 6:52 am, Nobody wrote:
> Without the p1.stdout.close(), if the reader (grep) terminates before
> consuming all of its input, the writer (ls) won't terminate so long as
> Python retains the descriptor corresponding to p1.stdout. In this
> situation, the p1.wait() will
On 2010-06-10, Chris Seberino wrote:
> How do subprocess.Popen("ls | grep foo", shell=True) with shell=False?
You'll have to build your own pipeline with multiple calls to subprocess
> Does complex commands with "|" in them mandate shell=True?
Yes.
Hey, I
On Thu, 10 Jun 2010 08:26:58 +0100
Simon Brunning wrote:
> On 10 June 2010 07:38, madhuri vio wrote:
> > i was wondering bout the usage and syntax of
> > grep command..can u tall me its syntax so that
> > i can use it and proceed...pls
>
> That's really
On Wed, 09 Jun 2010 21:15:48 -0700, Chris Seberino wrote:
> How do subprocess.Popen("ls | grep foo", shell=True) with shell=False?
The same way that the shell does it, e.g.:
from subprocess import Popen, PIPE
p1 = Popen("ls", stdout=PIPE)
p2 = Popen(["gr
On 10 June 2010 07:38, madhuri vio wrote:
>
> i was wondering bout the usage and syntax of
> grep command..can u tall me its syntax so that
> i can use it and proceed...pls
That's really not on topic for this list.
--
Cheers,
Simon B.
--
http://mail.python.org/mailman/listinfo/python-list
i was wondering bout the usage and syntax of
grep command..can u tall me its syntax so that
i can use it and proceed...pls
--
madhuri :)
--
http://mail.python.org/mailman/listinfo/python-list
On Wed, Jun 9, 2010 at 9:15 PM, Chris Seberino wrote:
> How do subprocess.Popen("ls | grep foo", shell=True) with shell=False?
I would think:
from subprocess import Popen, PIPE
ls = Popen("ls", stdout=PIPE)
grep = Popen(["grep", "foo"
How do subprocess.Popen("ls | grep foo", shell=True) with shell=False?
Does complex commands with "|" in them mandate shell=True?
cs
--
http://mail.python.org/mailman/listinfo/python-list
Mag Gam wrote:
> I am in the process of reading a zipped file which is about 6gb.
>
> I would like to know if there is a command similar to grep in python
> because I would like to emulate, -A -B option of GNU grep.
>
> Lets say I have this,
>
> 083828.441,AA
> 09
Mag Gam, 08.04.2010 14:21:
On Thu, Apr 8, 2010 at 7:31 AM, Stefan Behnel wrote:
Mag Gam, 08.04.2010 13:21:
I am in the process of reading a zipped file which is about 6gb.
I would like to know if there is a command similar to grep in python
because I would like to emulate, -A -B option of
t;
>> I would like to know if there is a command similar to grep in python
>> because I would like to emulate, -A -B option of GNU grep.
>>
>> Lets say I have this,
>>
>> 083828.441,AA
>> 093828.441,AA
>> 094028.441,AA
>> 094058.441,CC
>>
Mag Gam, 08.04.2010 13:21:
I am in the process of reading a zipped file which is about 6gb.
I would like to know if there is a command similar to grep in python
because I would like to emulate, -A -B option of GNU grep.
Lets say I have this,
083828.441,AA
093828.441,AA
094028.441,AA
I am in the process of reading a zipped file which is about 6gb.
I would like to know if there is a command similar to grep in python
because I would like to emulate, -A -B option of GNU grep.
Lets say I have this,
083828.441,AA
093828.441,AA
094028.441,AA
094058.441,CC
094828.441,AA
103828.441
On Thu, 03 Sep 2009 19:51:20 +0100, Jul wrote:
in tcsh terminal i have the following line of code
cat fileName.txt | grep "a"
which extracts all the instances of "a" from the file in the
terminal..
however when i am trying to create a txt while, i am unable to do so
for
On Thu, 2009-09-03 at 11:51 -0700, Jul wrote:
[Stuff about tcsh and grep deleted]
What on earth does this have to do with Python?
-a
--
http://mail.python.org/mailman/listinfo/python-list
in tcsh terminal i have the following line of code
cat fileName.txt | grep "a"
which extracts all the instances of "a" from the file in the
terminal..
however when i am trying to create a txt while, i am unable to do so
for some reason..this is the syntaxt i am using --
cat
Matthew Wilson wrote:
> I'm writing a command-line application and I want to search through lots
> of text files for a string. Instead of writing the python code to do
> this, I want to use grep.
>
> This is the command I want to run:
>
> $ grep -l foo dir
>
Matthew Wilson wrote:
consensus. I could os.popen, commands.getstatusoutput, the subprocess
module, backticks, etc.
Backticks do_not_do what you think they do.
And with py3k they're also as dead as a dead parrot.
--
http://mail.python.org/mailman/listinfo/python-list
On Thu 07 May 2009 09:25:52 AM EDT, Tim Chase wrote:
> While it doesn't use grep or external processes, I'd just do it
> in pure Python:
Thanks for the code!
I'm reluctant to take that approach for a few reasons:
1. Writing tests for that code seems like a fairly large am
On Thu 07 May 2009 09:09:53 AM EDT, Diez B. Roggisch wrote:
> Matthew Wilson wrote:
>>
>> As of May 2009, what is the recommended way to run an external process
>> like grep and capture STDOUT and the error code?
>
> subprocess. Which becomes pretty clear when readi
I'm writing a command-line application and I want to search through lots
of text files for a string. Instead of writing the python code to do
this, I want to use grep.
This is the command I want to run:
$ grep -l foo dir
In other words, I want to list all files in the directory dir
Matthew Wilson wrote:
> I'm writing a command-line application and I want to search through lots
> of text files for a string. Instead of writing the python code to do
> this, I want to use grep.
>
> This is the command I want to run:
>
> $ grep -l foo dir
>
>
I'm writing a command-line application and I want to search through lots
of text files for a string. Instead of writing the python code to do
this, I want to use grep.
This is the command I want to run:
$ grep -l foo dir
In other words, I want to list all files in the directory dir
Roy Smith:
> But, along those lines, I've often thought that split() needed a way to not
> just limit the number of splits, but to also throw away the extra stuff.
> Getting the first N fields of a string is something I've done often enough
> that refactoring the slicing operation right into the sp
In article <[EMAIL PROTECTED]>,
Peter Otten <[EMAIL PROTECTED]> wrote:
> Roy Smith wrote:
>
> > In article <[EMAIL PROTECTED]>,
> > Peter Otten <[EMAIL PROTECTED]> wrote:
> >
> >> > I might take it one step further, however, and do:
> >> >
> >> >> fields = line.split()[:2]
> >> >>
Roy Smith wrote:
> In article <[EMAIL PROTECTED]>,
> Peter Otten <[EMAIL PROTECTED]> wrote:
>
>> > I might take it one step further, however, and do:
>> >
>> >> fields = line.split()[:2]
>> >> a, b = map(int, fields)
>> >
>> > in fact, I might even get rid of the very generic,
In article
<[EMAIL PROTECTED]>,
[EMAIL PROTECTED] wrote:
> Roy Smith:
> > No reason to limit how many splits get done if you're
> > explicitly going to slice the first two.
>
> You are probably right for this problem, because most lines are 2
> items long, but in scripts that have to process li
In article <[EMAIL PROTECTED]>,
Peter Otten <[EMAIL PROTECTED]> wrote:
> > I might take it one step further, however, and do:
> >
> >> fields = line.split()[:2]
> >> a, b = map(int, fields)
> >
> > in fact, I might even get rid of the very generic, but conceptually
> > overkill,
Roy Smith:
> No reason to limit how many splits get done if you're
> explicitly going to slice the first two.
You are probably right for this problem, because most lines are 2
items long, but in scripts that have to process lines potentially
composed of many parts, setting a max number of parts sp
Roy Smith wrote:
> In article <[EMAIL PROTECTED]>,
> Peter Otten <[EMAIL PROTECTED]> wrote:
>
>> Without them it looks better:
>>
>> import sys
>> for line in sys.stdin:
>> try:
>> a, b = map(int, line.split(None, 2)[:2])
>> except ValueError:
>> pass
>> else:
>>
In article <[EMAIL PROTECTED]>,
Peter Otten <[EMAIL PROTECTED]> wrote:
> Without them it looks better:
>
> import sys
> for line in sys.stdin:
> try:
> a, b = map(int, line.split(None, 2)[:2])
> except ValueError:
> pass
> else:
> if a + b == 42:
>
hofer wrote:
> Something I have to do very often is filtering / transforming line
> based file contents and storing the result in an array or a
> dictionary.
>
> Very often the functionallity exists already in form of a shell script
> with sed / awk / grep , . . .
> and I w
ell script
> with sed / awk / grep , . . .
> and I would like to have the same implementation in my script
>
All that sed'ing, grep'ing and awk'ing, you might want to take a look
at pyparsing. Here is a pyparsing take on your posted problem:
from pyparsing import LineEnd,
On Tue, 02 Sep 2008 10:36:50 -0700, hofer wrote:
> sed 's/\.\..*//' \### remove '//' comments | sed 's/#.*//'
Comment does not match the code. Or vice versa. :-)
Untested:
from __future__ import with_statement
from itertools import ifilter, ifilterfalse, imap
def is_junk(line):
line
Hi,
Something I have to do very often is filtering / transforming line
based file contents and storing the result in an array or a
dictionary.
Very often the functionallity exists already in form of a shell script
with sed / awk / grep , . . .
and I would like to have the same implementation in
ot have
this property. "
Hmm, unfortunately it's still orders of magnitude slower than grep in my
own application that involves matching lots of strings and regexps
against large files (I killed it after 400 seconds, compared to 1.5 for
grep), and that's leaving aside the much longer compi
Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]>:
> On Mon, 07 Jul 2008 16:44:22 +0200, Sebastian \"lunar\" Wiesner wrote:
>
>> Mark Wooding <[EMAIL PROTECTED]>:
>>
>>> Sebastian "lunar" Wiesner <[EMAIL PROTECTED]> wrote:
>>>
# perl -e '("a" x 10) =~ /^(ab?)*$/;'
zsh: segmentation fau
1 - 100 of 246 matches
Mail list logo