Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'Execute selected text as python or perl' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Execute selected text as python or perl
Authored by: cedric on Mar 11, '05 12:55:17PM
While the idea is very clever (and I am a bit ashamed of not having thought of it first), I always thougt that Perl people are doing fixes the hard way.

You can use pbpaste, that's very cool. But you can do what you want simply by putting a

 | python - 
afterwards.

If, like me, you need some home-made definitions used thousands of times every day and stored in a file, you can set your

PYTHONSTARTUP
variable to a startup.py file saying
from my_module_with_1000_useful_defs import *

Then, use this:

 pbpaste | python -i 

Et voilĂ ! The -i ensures python starts up and reads the startup module, and your piece of code stored in pbpaste can now call any of the defs defined in your module. And no need for another cryptic Perl script.

[ Reply to This | # ]