Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #97313
| Path | csiph.com!eternal-september.org!feeder.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail |
|---|---|
| From | Cecil Westerhof <Cecil@decebal.nl> |
| Newsgroups | comp.lang.python |
| Subject | Only getting the first 6 lines |
| Date | Thu, 01 Oct 2015 23:58:49 +0200 |
| Organization | Decebal Computing |
| Lines | 15 |
| Message-ID | <87y4fmp7xi.fsf@Equus.decebal.nl> (permalink) |
| Mime-Version | 1.0 |
| Content-Type | text/plain |
| Injection-Info | mx02.eternal-september.org; posting-host="528adfd6ad074c92fdc6a7f8fb9e23d8"; logging-data="31815"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/1a5wZtSh8vfCs8o+CyMldvXJNgIXwsmA=" |
| User-Agent | Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) |
| X-Homepage | http://www.decebal.nl/ |
| Cancel-Lock | sha1:12iOR4ShoKD9YmekabvzSmd88L0= sha1:GtFpkRUfr+Z/zDUWEOybtPpVook= |
| Xref | csiph.com comp.lang.python:97313 |
Show key headers only | View raw
I want to get the first 6 lines of ps output. For this I use:
========================================================================
from subprocess import check_output
ps_command = ('ps', '-eo', 'user,pid,pcpu,pmem,stat,start,time,cmd', '--sort')
message = '\n'.join(check_output(ps_command + ('-%cpu',)).decode("utf-8").splitlines()[0:6])
========================================================================
It works, but does not look very efficient. Is there a better way to
do this?
--
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof
Back to comp.lang.python | Previous | Next — Next in thread | Find similar | Unroll thread
Only getting the first 6 lines Cecil Westerhof <Cecil@decebal.nl> - 2015-10-01 23:58 +0200
Re: Only getting the first 6 lines Ian Kelly <ian.g.kelly@gmail.com> - 2015-10-01 16:58 -0600
Re: Only getting the first 6 lines Cameron Simpson <cs@zip.com.au> - 2015-10-02 08:50 +1000
Re: Only getting the first 6 lines Cecil Westerhof <Cecil@decebal.nl> - 2015-10-02 13:08 +0200
Re: Only getting the first 6 lines Peter Otten <__peter__@web.de> - 2015-10-02 09:37 +0200
Re: Only getting the first 6 lines Cecil Westerhof <Cecil@decebal.nl> - 2015-10-02 13:11 +0200
csiph-web