Limit Lines of Output

B

Bryan Britten

Hey, group, quick (I hope) question:

I've got a simple script that counts the number of words in a data set (it's more complicated than that, but that's one of the functions), but there are so many words that the output is too much to see in the command prompt window. What I'd like to be able to do is incorporate the "More..." feature that help libraries have, but I have no idea how to do it. I also don't know if I'm asking the question correctly because a Google search yielding nothing.

Any insight would be appreciated. Thanks!
 
J

Joel Goldstick

Hey, group, quick (I hope) question:

I've got a simple script that counts the number of words in a data set
(it's more complicated than that, but that's one of the functions), but
there are so many words that the output is too much to see in the command
prompt window. What I'd like to be able to do is incorporate the "More..."
feature that help libraries have, but I have no idea how to do it. I also
don't know if I'm asking the question correctly because a Google search
yielding nothing.

Any insight would be appreciated. Thanks!

If you are using linux, you should look up the comand 'less'. It allows
you to page thru a test file. You can either write your list to a file or
pipe it into less (haven't tried that myself)
 
J

Joel Goldstick

Ah, I always forget to mention my OS on these forums. I'm running Windows.

I don't think I fully understand your problem. Why can't you send output
to a text file, then use a text editor to view results?
 
B

Bryan Britten

Joel -

I don't want to send it to a text file because it's just meant to serve as a reference for the user to get an idea of what words are mentioned. The words being analyzed are responses to a survey questions and the primary function of this script is to serve as a text analytics program. Exporting the output to a text file would just be an unnecessary/undesirable step for theuser.
 
I

Ian Kelly

Ah, I always forget to mention my OS on these forums. I'm running Windows.

Supposedly, Windows has "more"
[http://superuser.com/questions/426226/less-or-more-in-windows],

For Linux+less; this works:

from subprocess import Popen, PIPE
less = Popen("less", stdin=PIPE)
less.stdin.write(b"\n".join("This is line number
{}".format(i).encode("UTF-8") for i in range(1000)))
less.wait()


Or simply:

$ python my_script.py | less

It works the same way in Windows:

C:\> python my_script.py | more
 
G

Gene Heskett

Ah, I always forget to mention my OS on these forums. I'm running
Windows.

Supposedly, Windows has "more"
[http://superuser.com/questions/426226/less-or-more-in-windows],

Yes, but less is more than more.
For Linux+less; this works:

from subprocess import Popen, PIPE
less = Popen("less", stdin=PIPE)
less.stdin.write(b"\n".join("This is line number
{}".format(i).encode("UTF-8") for i in range(1000)))
less.wait()


Cheers, Gene
--
"There are four boxes to be used in defense of liberty:
soap, ballot, jury, and ammo. Please use in that order."
-Ed Howdershelt (Author)
My web page: <http://coyoteden.dyndns-free.com:85/gene> is up!
My views
<http://www.armchairpatriot.com/What Has America Become.shtml>
Campbell's Law:
Nature abhors a vacuous experimenter.
A pen in the hand of this president is far more
dangerous than 200 million guns in the hands of
law-abiding citizens.
 
D

Dave Angel

Joel -

I don't want to send it to a text file because it's just meant to serve as a reference for the user to get an idea of what words are mentioned. The words being analyzed are responses to a survey questions and the primary function of this script is to serve as a text analytics program. Exporting the output to a text file would just be an unnecessary/undesirable step for the user.

Your subject says you want to limit the lines of output. So after 25
lines, quit the program. Not too hard.

At the other extreme, your user wants to be able to scroll up or down
within the hundreds of lines, seeing 25 at a time, and wants to be able
to search for particular substrings, optionally with case-insensitivity,
and wants to be able to sort them by some criteria, or copy/paste some
portion elsewhere.

Write a spec that limits what you want, or you'll never finish the
project. And accept that if you want too much, you'll end up writing
the equivalent of a text editor before you're done.
 
C

Chris Angelico

I did not.

Beg pardon? It looked like an accurate citation to me - you quoted the
OP's second post, then added the line beginning "Supposedly". That's
what Gene quoted, so I'm not understanding this rejection.

ChrisA
 
S

Steven D'Aprano

I did not.

Unless there are two people called "Joshua Landau" with email address
<[email protected]>, I'm afraid that you did.

Here's the email that started the subthread, by Bryan Britten:

http://mail.python.org/pipermail/python-list/2013-June/650697.html

Your, or possibly your evil doppelganger's, reply to Bryan:

http://mail.python.org/pipermail/python-list/2013-June/650698.html

Followed by Gene's reply to your reply:

http://mail.python.org/pipermail/python-list/2013-June/650750.html

And your, or your evil doppelganger's, reply to Gene:

http://mail.python.org/pipermail/python-list/2013-June/650773.html
 
J

Joshua Landau

Unless there are two people called "Joshua Landau" with email address
<[email protected]>, I'm afraid that you did.

Ah, but as rusi has understood, I did not.

(Although "I did not" may itself be opining, that was not the quoted text.)

Hey, sometimes I just like being cryptic.
 
S

Steven D'Aprano

I guess Joshua is saying that saying ≠ opining

But it is. From WordNet:

opine
v 1: express one's opinion openly and without fear or
hesitation; "John spoke up at the meeting" [syn: opine,
speak up, speak out, animadvert, sound off]


Admittedly we cannot tell what Joshua's mental state was at the time he
responded to Bryan, he may have been absolutely terrified for all we
know, but there's no sign of this fear, and no reason to think that he
hesitated, given that his response came through a mere nine minutes after
Bryan's comment.

Or if you prefer the Collaborative International Dictionary of English:

Opine \O*pine"\, v. t. & i. [imp. & p. p. Opined; p. pr. & vb.
n. Opining.] [L. opinari, p. p. opinatus; akin to opinus
(in comp.) thinking, and perh. to E. apt: cf. F. opiner.]
To have an opinion; to judge; to think; to suppose. --South.
[1913 Webster]


[Or is he opining?]

That's just his opinion, man.

*wink*
 
J

Joshua Landau

I guess Joshua is saying that saying ≠ opining

But it is. From WordNet:

opine
v 1: express one's opinion openly and without fear or
hesitation; "John spoke up at the meeting" [syn: opine,
speak up, speak out, animadvert, sound off]

To give context;

Ah, I always forget to mention my OS on these forums. I'm running
Windows.

Supposedly, Windows has "more"
[http://superuser.com/questions/426226/less-or-more-in-windows],

Yes, but less is more than more.
For Linux+less; this works:

from subprocess import Popen, PIPE
less = Popen("less", stdin=PIPE)
less.stdin.write(b"\n".join("This is line number
{}".format(i).encode("UTF-8") for i in range(1000)))
less.wait()

As you can see, my quoted text contained no *opinions*, at least of
the nuance that "opine" refers to.
Admittedly we cannot tell what Joshua's mental state was at the time he
responded to Bryan, he may have been absolutely terrified for all we
know, but there's no sign of this fear, and no reason to think that he
hesitated, given that his response came through a mere nine minutes after
Bryan's comment.

That's taking a very analytic turn...

To clarify; I did have little hesitation but that was not the grounds
to my objection.
Or if you prefer the Collaborative International Dictionary of English:

Opine \O*pine"\, v. t. & i. [imp. & p. p. Opined; p. pr. & vb.
n. Opining.] [L. opinari, p. p. opinatus; akin to opinus
(in comp.) thinking, and perh. to E. apt: cf. F. opiner.]
To have an opinion; to judge; to think; to suppose. --South.
[1913 Webster]

As this accurately sums up, to "opine" requires one to "judge" in some
form, or to be "opinionated"; these are not things I did; I rather
just referenced someone's work without openly judging it and stated
(objectively so, you shall find) that some code worked.
[Or is he opining?]

That's just his opinion, man.

*wink*
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,074
Latest member
StanleyFra

Latest Threads

Top