Can i use this script as a python evaluator?

Steven D'Aprano steven at REMOVE.THIS.cybersource.com.au
Tue Oct 21 05:33:56 CEST 2008


On Tue, 21 Oct 2008 11:22:56 +0800, Peter Wang wrote:

> Nathan Seese <uninverted at lavabit.com> writes:
> 
>>> #! /bin/sh
>>> python -c "import sys;exec(sys.stdin)"
>>
>> I know this isn't your question, but I think you could write that more
>> cleanly with:
>>
>> #!/usr/bin/python
>> import sys
>> exec(sys.stdin)
>
> thanks.
> What's the difference between this and mine?

Yours launches an new shell, which then calls python, which then executes 
whatever it finds in stdin as Python code.

The second one just launches Python directly.



> I think what i need actually is a python function like
> `file_get_contents' in php:)


I think that would be:

contents = open(filename).read()




-- 
Steven



More information about the Python-list mailing list