One line command line filter

Terry Reedy tjreedy at udel.edu
Mon Sep 5 19:02:04 EDT 2011


On 9/5/2011 5:32 PM, Jon Redgrave wrote:
>>> Am I missing something obvious?
>>
>> ls | python -c "for line in __import__('sys').stdin: print (line.upper())"
>
> Ah, so I am missing something - it is possible - but 'obvious'?
> Do people think it should be more accessible

__import__ is well-documented and is listed in the index of the builtin 
functions chapter. "Direct use of __import__() is rare, except in cases 
where you want to import a module whose name is only known at runtime." 
could be explanded to include "or where you want to import as part of an 
expression"

Every Python programmer should peruse that chapter to learn what is 
available for possible future use.

-- 
Terry Jan Reedy




More information about the Python-list mailing list