Feature idea / request

12 views
Skip to first unread message

Guy Adini

unread,
Sep 6, 2012, 11:27:48 AM9/6/12
to pyth...@googlegroups.com
Hi all,

I would like to discuss the idea of allowing pythonect to interpret shell commands.

I was thinking of an ipython-like syntax, where a command starting with an exclamation mark is considered a shell command,
and the result returned as a tuple - one result per line of output.
For example:
!ls *.png -> my_module.resize_and_save()

But this would be a problem with pipes. For example, I would like to do:

!cat /etc/apache2 | grep python -> [print, my_email_script, log_to_file]

And I don't want the pipe to be interpreted as a pythonect synchronous operator.

Any suggestions?

Once we define a syntax for this, I will try to implement it (if I manage to tackle the PLY part :)).



Itzik Kotler

unread,
Sep 6, 2012, 11:35:13 AM9/6/12
to pyth...@googlegroups.com
Single backticks (i.e. ` ... `) are currently reserved for Pythonect expression substitution

i.e. sum(`range(1,5) -> _**_`)

I can suggest double backticks (i.e. `` ... ``) for Shell expression substitution.

i.e. ``ls /bin`` -> _.startswith('p') -> print (roughly equal to: `ls /bin | grep p`)

Having said that, the question here whether it's a true language feature, an extension (???), or simply a function.

What do we expect Windows or Mobile users to do with a built-in feature that is not working (due to their Shell?)?




--
 
 

nir izraeli

unread,
Sep 6, 2012, 12:20:28 PM9/6/12
to pyth...@googlegroups.com
It seems to me like the best way to do something like that would be to pipe into a python (or pythonect) interpreter.
i.e. in any *nix shell:
$: ls /bin | python -m sys -c print(line) for line in sys.stdin if 'p' in line
(or any pythonect interpreter and syntax)

and that seems unrelated to either python or pythonect.
what's wrong with that?

- Nir

btw,  ``ls /bin`` -> 'p' in _ -> print resembles `ls /bin | grep p` better :)

--
 
 

Guy Adini

unread,
Sep 6, 2012, 12:30:47 PM9/6/12
to pyth...@googlegroups.com
@Nir:
It's just a matter of convenience.
I think of pyhonect as a sys-admin's super scripting tool (among other things), where you want to write 
pythonect scripts and execute them directly, and the scripts themselves should contain all relevant information.

I know that there's always a workaround, but I would also really enjoy using a language that gives me 
the cleanest, most intuitive syntax.

@Itsik:
I was thinking of a "use local shell" feature.
I don't think this is strange for OS's without a UNIX shell - they have the same problem
when they try to use Python's subprocess module and so forth. 

You both seem opposed though - that probably pushes it down in the to-do list...




--
 
 

Itzik Kotler

unread,
Sep 6, 2012, 12:52:16 PM9/6/12
to pyth...@googlegroups.com
I think the bar to make something a part of the language (i.e. incorporating it into a syntax) is much higher than developing a built-in function, or extending the standard library to include it.

I'd say the need to keep Pythonect simple overcomes this specific need (and especially since there are multiple workarounds).

--
 
 

Reply all
Reply to author
Forward
0 new messages