[Tutor] Re: [Tutor]Question on python

Derrick 'dman' Hudson dman@dman.ddts.net
Wed Nov 20 23:32:01 2002


--82I3+IH0IqGh5yIs
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On Thu, Nov 21, 2002 at 06:01:25AM +0530, sachin mehra wrote:
|=20
| Hi,
| Well I want to use the following commands:
| tr -cs '[:aplha:]' '[\n*]' < *.txt | uniq -c | sort -rm | more

If you want to use shell commands, why not just write a shell script?
I use shell scripts for shell-type operations and python for things
that aren't well suited for shell scripts.

| Which would give me a count of unique words in a .txt file..

How about this?
    http://www.uselesspython.com/count.py

    (found from http://www.uselesspython.com/uselesspython4.html)

| How can i use this..I have already tried the os.system option!!

os.system( "/bin/sh -c 'tr ...'" )

You need to run the shell command in a shell.

| I may need to use this command(or similar type) a few more times..

#!/bin/bash
# (I'm not sure if this runs in /bin/sh or if it requires bash)
for $((i=3D0 ; i<3 ; i+=3D1)) ; do
    tr -cs '[:aplha:]' '[\n*]' < *.txt | uniq -c | sort -rm | more
done

| How can I do it in python?

for _ in range( 3 ) :
    os.system( "/bin/sh -c 'tr ...'" )


It would be easier to suggest a solution if we knew the problem you
are trying to solve and what context it is in.  It's possible that
there is a better solution or a better way to do it.

Also take note of Danny's mention of the error in the shell command.

HTH,
-D

--=20
"...the word HACK is used as a verb to indicate a massive amount
of nerd-like effort."  -Harley Hahn, A Student's Guide to Unix
=20
http://dman.ddts.net/~dman/

--82I3+IH0IqGh5yIs
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: For info see http://www.gnupg.org

iEYEARECAAYFAj3cZOoACgkQO8l8XBKTpRR+PwCeMeg7CJgbagdd+BpEbDLBehcN
XCkAn0ZaPbnyT4CpnrTTaTsZQU2/bbbs
=1Ppm
-----END PGP SIGNATURE-----

--82I3+IH0IqGh5yIs--