By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
439,941 Members | 1,789 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 439,941 IT Pros & Developers. It's quick & easy.

python shell

P: n/a
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.

May 16 '07 #1
Share this Question
Share on Google+
12 Replies


P: n/a
* 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
May 16 '07 #2

P: n/a
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?

May 16 '07 #3

P: n/a
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

May 17 '07 #4

P: n/a
On May 16, 6: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.
Doctest!
http://en.wikipedia.org/wiki/Doctest
http://aspn.activestate.com/ASPN/Coo.../Recipe/305292

- Paddy.

May 19 '07 #5

P: n/a
In article <11**********************@u30g2000hsc.googlegroups .com>,
Paddy <pa*******@googlemail.comwrote:
>On May 16, 6: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.

Doctest!
http://en.wikipedia.org/wiki/Doctest
May 20 '07 #6

P: n/a
Cameron Laird wrote:
In article <11**********************@u30g2000hsc.googlegroups .com>,
Paddy <pa*******@googlemail.comwrote:
>On May 16, 6: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.
Doctest!
http://en.wikipedia.org/wiki/Doctest
.
.
.
<URL: http://en.wikipedia.org/wiki/DocTest will probably prove more fruitful.

While I don't like follow-ups which consist of trivial corrections, I *very*
much want to encourage readers to explore Doctest more deeply; it deserves the
attention, even at the cost of appearing pedantic.
Is there some mistake in this post? I find that there *is* an article at

http://en.wikipedia.org/wiki/Doctest

but that

http://en.wikipedia.org/wiki/DocTest

doesn't refer to an extant article. Since you claim to be exercising
your pedantry, I wonder why I get the results I do. Since we *are* being
pedantic, by the way, surely the name is actually "doctest", not "Doctest".

regards
Steve
--
Steve Holden +1 571 484 6266 +1 800 494 3119
Holden Web LLC/Ltd http://www.holdenweb.com
Skype: holdenweb http://del.icio.us/steve.holden
------------------ Asciimercial ---------------------
Get on the web: Blog, lens and tag your way to fame!!
holdenweb.blogspot.com squidoo.com/pythonology
tagged items: del.icio.us/steve.holden/python
All these services currently offer free registration!
-------------- Thank You for Reading ----------------

May 20 '07 #7

P: n/a
Krypto 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.
I'm not sure this will help - but!

I use a text editor (EditPlus under Windows) as a mini IDE. Some text
editors have a concept of "tools" where you can run the "tool" from
within the editor and it calls an external program to run the source
code in the editor. With EditPlus the tool looks something like:

Menu text: Python
Command: C:\Python25\python.exe
Argument: "$(FileName)"
Initial directory: $(FileDir)
Capture output: [X]

Output from the program run is captured in an "output window". A full
blown IDE it ain't but handy it is.

Regards,
Peter
--
Peter Anderson

There is nothing more difficult to take in hand, more perilous to
conduct, or more uncertain in its success, than to take the lead in the
introduction of a new order of things &mdash; Niccolo Machiavelli, "The
Prince", ch. 6
May 20 '07 #8

P: n/a
On Sat, 19 May 2007 21:42:27, Steve Holden <st***@holdenweb.comwrote
http://en.wikipedia.org/wiki/Doctest
>Since you claim to be exercising your pedantry, I wonder why I get the
results I do. Since we *are* being pedantic, by the way, surely the
name is actually "doctest", not "Doctest".
Yes, as the page you are referring to mentions right at the top:

,----------------
| Doctest
| From Wikipedia, the free encyclopedia
|
| The correct title of this article is doctest. The initial letter
is shown
| capitalized due to technical restrictions.
`----------------

--
Doug Woodrow

May 20 '07 #9

P: n/a
On May 20, 1:56 am, cla...@lairds.us (Cameron Laird) wrote:
In article <1179552984.466321.137...@u30g2000hsc.googlegroups .com>,Paddy <paddy3...@googlemail.comwrote:
On May 16, 6: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.
Doctest!
http://en.wikipedia.org/wiki/Doctest

.
.
.
<URL:http://en.wikipedia.org/wiki/DocTestwill probably prove more fruitful.

While I don't like follow-ups which consist of trivial corrections, I *very*
much want to encourage readers to explore Doctest more deeply; it deserves the
attention, even at the cost of appearing pedantic.
Sometimes you have to mess with the case of letters in wiki pages
which is the case here, but I did actually cut-n-paste the address
from Wikipedia as I like to look at the page from time to time as,
like yourself, I think doctest shows the true spirit of what is
Pythonic, and created the page when I found Wikipedia did not have it.

Gets me thinking along the lines of "What else should the intermediate
Python programmer know about"?
The other Python tool I am apt to carp on about is Kodos
http://kodos.sourceforge.net/ .
Kodos is a great tool for those new to reguar expressions. It allows
you to test your regular expressions on snippets of text and gives
great visual feedback on the results. After over a decade of writing
regexps I still use Kodos occasionally, and wish I had such a tool a
decade ago.

- Paddy.

May 20 '07 #10

P: n/a
Douglas Woodrow wrote:
On Sat, 19 May 2007 21:42:27, Steve Holden <st***@holdenweb.comwrote
> http://en.wikipedia.org/wiki/Doctest
>Since you claim to be exercising your pedantry, I wonder why I get the
results I do. Since we *are* being pedantic, by the way, surely the
name is actually "doctest", not "Doctest".

Yes, as the page you are referring to mentions right at the top:

,----------------
| Doctest
| From Wikipedia, the free encyclopedia
|
| The correct title of this article is doctest. The initial letter
is shown
| capitalized due to technical restrictions.
`----------------
Whereas Cameron wrote
... to explore Doctest more deeply ...
regards
Steve
--
Steve Holden +1 571 484 6266 +1 800 494 3119
Holden Web LLC/Ltd http://www.holdenweb.com
Skype: holdenweb http://del.icio.us/steve.holden
------------------ Asciimercial ---------------------
Get on the web: Blog, lens and tag your way to fame!!
holdenweb.blogspot.com squidoo.com/pythonology
tagged items: del.icio.us/steve.holden/python
All these services currently offer free registration!
-------------- Thank You for Reading ----------------

May 20 '07 #11

P: n/a
On May 17, 3:38 am, Krypto <krypto.wiz...@gmail.comwrote:
My mentor told me that you can virtually do anything from
testing your program to anything in the shell. Any incite
would be useful.
Using something like tee you can run the Python script in
the shell and also capture it's output:

http://unxutils.sourceforge.net/

For example, here are details on how to use tee within
the Zeus IDE:

http://www.zeusedit.com/forum/viewtopic.php?t=74

Jussi Jumppanen
Author: Zeus for Windows IDE
http://www.zeusedit.com - Zeus for Windows Programmer's IDE

May 20 '07 #12

P: n/a
In article <11**********************@y80g2000hsf.googlegroups .com>,
Paddy <pa*******@googlemail.comwrote:
May 22 '07 #13

This discussion thread is closed

Replies have been disabled for this discussion.