473,748 Members | 6,161 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

python shell

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
12 2475
* 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
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\use r>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("facto r! 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
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\use r>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("facto r! 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
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
In article <11************ **********@u30g 2000hsc.googleg roups.com>,
Paddy <pa*******@goog lemail.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
Cameron Laird wrote:
In article <11************ **********@u30g 2000hsc.googleg roups.com>,
Paddy <pa*******@goog lemail.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.blogs pot.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
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\pyt hon.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
On Sat, 19 May 2007 21:42:27, Steve Holden <st***@holdenwe b.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
On May 20, 1:56 am, cla...@lairds.u s (Cameron Laird) wrote:
In article <1179552984.466 321.137...@u30g 2000hsc.googleg roups.com>,Padd y <paddy3...@goog lemail.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.or g/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

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

54
6569
by: Brandon J. Van Every | last post by:
I'm realizing I didn't frame my question well. What's ***TOTALLY COMPELLING*** about Ruby over Python? What makes you jump up in your chair and scream "Wow! Ruby has *that*? That is SO FRICKIN' COOL!!! ***MAN*** that would save me a buttload of work and make my life sooooo much easier!" As opposed to minor differences of this feature here, that feature there. Variations on style are of no interest to me. I'm coming at this from a...
4
3847
by: Logan | last post by:
Several people asked me for the following HOWTO, so I decided to post it here (though it is still very 'alpha' and might contain many (?) mistakes; didn't test what I wrote, but wrote it - more or less - during my own installation of Python 2.3 on Fedora Core 1 Linux for a friend of mine). Anyway, HTH, L.
20
5193
by: Matthew Thorley | last post by:
My friend sent me an email asking this: > I'm attemtping to decide which scripting language I should master and > was wondering if it's possible to do > these unixy awkish commands in python: > > How to find the amount of disk space a user is taking up: > > find / -user rprice -fstype nfs ! -name /dev/\* -ls | awk '{sum+=$7};\ > {print "User rprice total disk use = " sum}'
2
4545
by: Xah Lee | last post by:
Python Doc Problem Example: os.system Xah Lee, 2005-09 today i'm trying to use Python to call shell commands. e.g. in Perl something like output=qx(ls) in Python i quickly located the the function due to its
30
2912
by: bblais | last post by:
Hello, Let me start by saying that I am coming from a background using Matlab (or Octave), and C++. I am going to outline the basic nuts-and-bolts of how I work in these languages, and ask for some help to find out how the same thing is done in Python. I am not sure what the standard is. In C++, I open up an editor in one window, a Unix shell in another. I write the code in the editor, then switch to the shell window for compile...
16
3946
by: John Salerno | last post by:
Hi all. I just installed Ubuntu and I'm learning how to use the bash shell. Aside from the normal commands you can use, I was wondering if it's possible to use Python from the terminal instead of the normal bash commands (e.g. print instead of echo). My main reason for asking is that I like using Python for everything, and if I don't need to learn the bash 'language', then I won't just yet. Thanks.
9
2570
by: TP | last post by:
Hi everybody, I am new to Python, I try to understand how Python treats special characters. For example, if I execute the following line in a shell console, I obtain a colored string: $ python -c "print '\033 ColorReset = os.environ Esc = os.environ print '%s%s%s%s%s' % (Esc, Color, " foo ", Esc, ColorReset)
0
3474
by: Cameron Simpson | last post by:
On 17Aug2008 21:25, John Nagle <nagle@animats.comwrote: Because $HOSTNAME is a bash specific variable, set by bash but NOT EXPORTED! Like $0 and a bunch of other "private" variables, subprocesses do not inherit this value. From "man bash": Shell Variables The following variables are set by the shell:
3
3951
by: mmm | last post by:
I am looking for advice on Python Editors and IDEs I have read other posts and threads on the subject and my two questions at this time are mainly about the IDLE-like F5-run facilities. While I am fairly happy using IDLE, the debugger is unintuitive to me and I wanted a project manager and a better variable/ class browser and also the potential to edit/run other languages such as R and Tex/Latex. Windows and LINUX compatibility is...
8
5583
by: james.kirin39 | last post by:
Hi everyone, After having used Python on Linux for some time, I now have to do Python coding on Windows. I am big fan of the interactive Python shell to test, eg, regexps. Is there an interactive Python shell on Windows that supports: - easy copy-pasting to/from an editor? (as opposed to the cumbersome "mark", "copy" and then "paste" sequence that any terminal on Windows
0
8989
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9537
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9367
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9319
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9243
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
4869
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3309
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2780
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2213
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.