python shell

mensanator at aol.com mensanator at aol.com
Wed May 16 18:59:12 EDT 2007


On May 16, 12:38 pm, Krypto <krypto.wiz... at gmail.com> wrote:
> I have been using python shell to test small parts of the big program.
> What other ways can I use the shell effectively. My mentor told me
> that you can virtually do anything from testing your program to
> anything in the shell. Any incite would be useful.

Yeah? Well tell your mentor he can take his programs and
his literal interpretaions to the other side of the river!!

Oh...wait. Did you mean "insight"?

One thing that covers a LOT of ground is you can run other
programs from the shell and capture their output (assuming
the output is text to stdout).

For example, I can run the program factor!.exe from the
command line:

C:\python25\user>factor!.exe 27
PRIME_FACTOR     3
PRIME_FACTOR     3
PRIME_FACTOR     3

But I can also run it from the Python shell:

>>> import os
>>> f = os.popen("factor! 27").readlines()

>>> f
['PRIME_FACTOR     3\n', 'PRIME_FACTOR     3\n', 'PRIME_FACTOR
3\n']

>>> q = [int(i.split()[1]) for i in f]
>>> q
[3, 3, 3]

Now, you've got the factors without having to write your own
factoring program and you never had to leave the shell.

What more could you ask for?




More information about the Python-list mailing list