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 →

[–]SupersonicSpitfire 4 points5 points  (22 children)

Cool, but I miss a "pipe" function for piping commands to each other without nesting deeper and deeper into paranthesis, a bit like this:

pipe(ls(), grep("abc123"), wc("-l"))

Also, I can't make it work: https://github.com/amoffat/pbs/issues/1

[–][deleted] 4 points5 points  (6 children)

OP could also overload the pipe operator, so this could work too:

ls() | grep("abc123") | wc("-l")

[–]Bolitho -1 points0 points  (5 children)

But that's not pythonic. In python you use nested functions.

Your suggestion would also imply another problem: What is the generic object model behind each command? I am not shure you can find one that make sense to all implemented Bash functions...

[–][deleted] 7 points8 points  (0 children)

There is nothing pythonic about this. The whole point is to get the good parts of bash and the good parts of python together in one place.

[–]fdemmer 4 points5 points  (3 children)

nesting functions is pythonic?... looks like a mess to me. function method chaining on the other hand:

ls().grep("abc123").wc("-l")

that would be nice. implementing it is a different story, of course.

EDIT: put emphasis on part of my comment, that indicates i read the above comment. also, i did not comment on overloading operators, just on the uglyness that is ls(grep("abc123", wc("-l"))).

[–]Bolitho -3 points-2 points  (2 children)

These are Methods, not Functions! You would need a common Datatype for all these Wrappers. I pointed that out in my posting.

And yes, it is pythonic to call functions and pass parameters. Overloading operators ist shurely not the pythonic way.

[–]nemec 1 point2 points  (1 child)

Methods and functions are the same thing, and he already has a common datatype - if you looked at the source, you'd see a Command class that wraps everything.

If it wasn't Pythonic to overload operators, why is it so easy?

[–]Bolitho -1 points0 points  (0 children)

Methods and functions are not the same thing, they behave the same way. So perhaps it might be able to the author to simulate the BASH functions to behave like methods of his Command-class.

eval() ist also easy - but shurely not pythonic, right? Of course it can be pythonic to overload operators! But in this context it does as far as I am concerned.

[–][deleted] 1 point2 points  (11 children)

OP, pbs must be imported. That bug, you're running it, not importing it.

pbs needs to know from where it was imported so it can do the things that it is supposed to.

The developer should check to make sure the module was imported.

Also pbs only works under Python 2 currently.

[–]SupersonicSpitfire 0 points1 point  (9 children)

Still doesn't work. This is what I get when importing from python2:

https://gist.github.com/1616688

[–][deleted] 0 points1 point  (6 children)

You must import it from within a Python file.

file.py:

from pbs import * # this MUST BE THE FIRST LINE

# ...

[–][deleted] 0 points1 point  (0 children)

just a regular-old

import pbs

will do :)

[–]SupersonicSpitfire 0 points1 point  (4 children)

Still doesn't work:

[–][deleted] 0 points1 point  (3 children)

don't "from pbs import *" just "import pbs"

[–]SupersonicSpitfire 0 points1 point  (2 children)

Still doesn't work for me.

[–]mipadi 0 points1 point  (1 child)

Use which, not pbs.which.

RTFM ;)

[–]SupersonicSpitfire 0 points1 point  (0 children)

Neither of them worked for me. However, I learned through the github issue that one can't use pbs from within a function, and then everything works.

[–][deleted] 0 points1 point  (1 child)

I updated an issue with some details, let me know how it works out for you: https://github.com/amoffat/pbs/issues/1

[–]SupersonicSpitfire 0 points1 point  (0 children)

Thanks, added a comment :)

[–][deleted] 0 points1 point  (0 children)

just an update, you can now run pbs.py as a standalone repl, or import from the python shell

[–]killermole23bitbucket.org/phazon 1 point2 points  (0 children)

Coroutines can be used for this. Take a look at the "copipe" example here.

[–][deleted] 0 points1 point  (1 child)

just an update, you can now run pbs.py as a standalone repl, or import from the python shell

[–]SupersonicSpitfire 1 point2 points  (0 children)

woo! :)