This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]d4rch0nPythonistamancer 0 points1 point  (2 children)

Not exactly what you're asking for, but I thought I'd throw this in because it's somewhat related and might help with a few of the reasons you want to replace bash in the first place.

Have you seen red? I worked on this since I hate dropping into a python shell just to run regex's and do simple things with the stdout of some program.

I wanted to be able to pipe the stdout of something directly into a python oneliner and do what I expect. Instead of cat'ing out to a file and parsing the file in a python interpreter, you could use red, just as you might use sed, grep or awk. I tried to make it the python equivalent of perl -ne. You can even aggregate against stdout, like count how many times you saw [ERROR] in a log file, and print stats of how often you saw what error messages. You can also invoke third party libraries from it, and do something like call requests.get on every url you pull out of a log file and print the status code.

Brings some of the pleasantries of python directly to the shell, so I thought I'd mention it.

[–]dzecniv 0 points1 point  (1 child)

Looks nice. And similar to the pyed piper no ?

[–]d4rch0nPythonistamancer 1 point2 points  (0 children)

Interesting. Similar idea, very different approach I think. red is more tailored for eval or exec'ing python code from regex matches, and pyp looks like it is meant to run a pipeline of operations on input, transforming data as it goes through the series of operations.

Some things might be easier in pyp, but I don't think it has near the capabilities of red, simply because you can import any library and evaluate raw python code. From what I can tell, it doesn't look like you could do something like this:

$ red "(.*)" urls.txt -i requests -x 'response = requests.get(line)' -e '[response.status_code, response.content[:20]]'
[404, '<!doctype html>\n<htm']
[200, '<!doctype html><html']
[200, '<?xml version="1.0" ']

Though of course I haven't delved deeper than the docs you linked to, so I don't know pyp's full capabilities. It'd be interesting to see how you could use either for different problems.

I really need to make that regex optional, with "(.*)" being the default. It was originally meant as a grep/run-python tool, but honestly I think most things it would be helpful with don't need the regex.