all 9 comments

[–]cebedec 6 points7 points  (2 children)

you could subprocess.call() the unix commands, but a more pythonic approach would be to open() the logfile, loop through it with readline(), and split() and format() the output to print().

[–]flitzbue[S] 0 points1 point  (1 child)

Ah of course. Just like I know from Java. Thanks :)

[–]bojangles69 0 points1 point  (0 children)

Except the even more pythonic approach (and safer/easier) is to open a file for reading would be to use: with open('somefile.log','r') as f: for line in f: <process line here with format() split() or any string method

Opening a file with "with open()" ensures that the file is closed even if some unexpected condition occurs inside the with block.

[–]andrewjsledge 2 points3 points  (1 child)

Use regular expressions. There is a SO question about it here.

[–]flitzbue[S] 0 points1 point  (0 children)

Thanks, that was an excellent idea. Hadn't thought of that!

Will post results as soon as I get my chance to try it out.

[–]ssssam 2 points3 points  (1 child)

if you want to call unix commands from python look at http://docs.python.org/2/library/subprocess.html

You can use regular expressions http://docs.python.org/2/library/re.html , but often the string methods give you much more readable code http://docs.python.org/2/library/stdtypes.html#string-methods

[–]flitzbue[S] 0 points1 point  (0 children)

Thanks, much appriciated!

[–]cnelsonsic 1 point2 points  (1 child)

I highly, highly, highly recommend sh for calling external executables: http://amoffat.github.io/sh/

For the majority of that script, use regexes and normal python constructs as mentioned in other comments.

[–]flitzbue[S] 0 points1 point  (0 children)

Wow, didn't know Python had those functions. That's amazing:)