python shell [英] python shell

查看:65
本文介绍了python shell的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在使用python shell来测试大程序的一小部分。

还有哪些其他方法可以有效地使用shell。我的导师告诉我

你几乎可以做任何事情,从测试你的程序到shell中的
。任何煽动都会有用。

解决方案

* Krypto(2007年5月16日10:38:27 -0700)
< blockquote class =post_quotes>
我一直在使用python shell来测试大程序的一小部分。

还有哪些其他方法可以有效地使用shell。我的导师告诉我

你几乎可以做任何事情,从测试你的程序到shell中的
。任何煽动都会有用。



使用IPython


5月16日下午12:38,Krypto< krypto.wiz .. 。@ gmail.comwrote:


我一直在使用python shell来测试大程序的一小部分。

还有什么方法可以有效地使用shell。我的导师告诉我

你几乎可以做任何事情,从测试你的程序到shell中的
。任何煽动都会有用。



是吗?那么告诉你的导师,他可以把他的课程和他的文字解释给他们带到河的另一边!!


哦......等等。你的意思是洞察力吗?


有一件事可以解决很多问题,你可以从shell运行其他

程序并捕获它们的输出(假设

输出是文本到stdout)。


例如,我可以从
$ b $运行程序因子!.exe b命令行:


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

PRIME_FACTOR 3

PRIME_FACTOR 3

PRIME_FACTOR 3

但我也可以从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]

现在,你已经掌握了这些因素而无需自己编写

保理程序,你永远不必离开外壳。


您还能要求什么?


me********@aol.com < me ******* *@aol.comwrote:


5月16日下午12:38,Krypto< krypto.wiz ... @ gmail.comwrote:
< blockquote class =post_quotes>
>我一直在使用python shell来测试大程序的一小部分。
我可以有效地使用shell的其他方法。我的导师告诉我,你几乎可以做任何事情,从测试你的程序到shell中的任何东西。任何煽动都会有用。


是吗?那么告诉你的导师他可以把他的节目和他的文字解释带到河的另一边!


哦......等等。你的意思是见解吗?


有一件事可以解决很多问题,你可以从shell运行其他

程序并捕获它们的输出(假设

输出是stdout的文本)。


例如,我可以从

命令行运行程序因子!.exe:


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

PRIME_FACTOR 3

PRIME_FACTOR 3

PRIME_FACTOR 3


但我也可以从Python shell运行它:


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


> ;>> f



[''PRIME_FACTOR 3 \''',''PRIME_FACTOR 3 \ n'',''PRIME_FACTOR

3 \ n'']


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



[3,3,3]


现在,你已经掌握了这些因素而无需编写自己的

保理程序,而且你永远不必离开shell。


您还能要求什么?



我可以要求一些技巧让我做一些事情:


* os.fork() - - 但是它产生了它自己的xterm / shell

所以我不能分别与每个孩子互动


*使用curses库---翻译来自

一个shell / xterm和curses显示控制另一个

一个。


我' 我相信他们在那里......而且我很乐意看到他们的指示。



-

吉姆丹尼斯,

Starshine:签名,密封,交付


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.

解决方案

* Krypto (16 May 2007 10:38:27 -0700)

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.

use IPython


On May 16, 12:38 pm, Krypto <krypto.wiz...@gmail.comwrote:

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?


me********@aol.com <me********@aol.comwrote:

On May 16, 12:38 pm, Krypto <krypto.wiz...@gmail.comwrote:

>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?

I could ask for some tricks that would let me do things like:

* os.fork() --- but have that spawned in it''s own xterm/shell
so I can no interact with each of the children separately

* Use the curses library --- with the interpreter reading from
one shell/xterm and the curses display controlling another
one.

I''m sure they''re out there ... and I''ve love to see pointers to them.


--
Jim Dennis,
Starshine: Signed, Sealed, Delivered


这篇关于python shell的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆