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
well-named-ness:
import os
os.system("ls")
however, according to the doc http://www.python.org/doc/2.4/lib/os-process.html the os.system()
returns some esoteric unix thing, not the command output. The doc
doesn't say how to get the output of the command.
by chance someone told me that in python 2.4 the os.system is
supplanted by subprocess.call(), but this isn't mentioned in the doc!
upon finding the new doc location http://www.python.org/doc/2.4/lib/mo...ubprocess.html i'm told that
this module replaces:
os.system
os.spawn*
os.popen*
popen2.*
commands.*
interesting. Since i'm not Python expert, i like to look at these. But
fuck, the incompetent doc gives ample gratis links to OpenSource this
or that or author masturbation links to remote book i don't really care
about, but here there's no link.
Problem summary:
* does not focus on the task users need to do. Instead, the doc is
oriented towards tech geeking.
* does not inform the reader at the right place where a new function is
replacing the old.
* does not provide relevant cross-links. (while provding many
irrelevant links because of OpenSource or Tech Geeking fanaticism)
Solution Suggestion:
* Add examples.
* Add cross-links to relevant modules.
* Mention and add link at the right place supplanted functions.
* Orient the doc to tasks and manifest functionalities. Think like
functional programing: input and output specification, and document
them. This will help focus and precision in the doc. Avoid prose-like
descriptions. Avoid drilling on remotely related tech/unix/C esoterica.
e.g. Do not mention as a documentation how they are implemented.
Mention implementation on the side if necessary. This way, the language
becomes focused as a independent tool (e.g. Mathematica, Java, Scheme,
emacs) (which may provide ample capabilities to interface/connect to
other technologies), instead of heavily intermixed and dependent with a
bunch of other things (unix things: Perl, Apache, shells).
-----------------------------
This article is archive at: http://xahlee.org/UnixResource_dir/w...on_doc_os.html
Xah xa*@xahlee.org
∑ http://xahlee.org/ 2 4484
Xah Lee wrote: 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 well-named-ness:
import os os.system("ls")
however, according to the doc http://www.python.org/doc/2.4/lib/os-process.html the os.system() returns some esoteric unix thing, not the command output.
"""
*system*( command)
Execute the command (a string) in a subshell. This is implemented by
calling the Standard C function system(), and has the same
limitations. Changes to |posix.environ|, |sys.stdin|, etc. are not
reflected in the environment of the executed command.
On Unix, the return value is the exit status of the process encoded
in the format specified for wait(). Note that POSIX does not specify
the meaning of the return value of the C system() function, so the
return value of the Python function is system-dependent.
On Windows, the return value is that returned by the system shell
after running command, given by the Windows environment variable
COMSPEC: on *command.com* systems (Windows 95, 98 and ME) this is
always |0|; on *cmd.exe* systems (Windows NT, 2000 and XP) this is
the exit status of the command run; on systems using a non-native
shell, consult your shell documentation.
Availability: Unix, Windows.
"""
Yup. Nothing more esoteric than a process's exit status. That's one of
those really tricky jargons that computer scientist idiots like to throw
around. You've got to watch out for those.
The doc doesn't say how to get the output of the command.
by chance someone told me that in python 2.4 the os.system is supplanted by subprocess.call(), but this isn't mentioned in the doc!
I'm presuming you mean in the os.system docs as you mention below that
you found such documentation.
upon finding the new doc location http://www.python.org/doc/2.4/lib/mo...ubprocess.html i'm told that this module replaces:
os.system os.spawn* os.popen* popen2.* commands.*
interesting.
"""
6.8 subprocess -- Subprocess management
New in version 2.4.
The subprocess module allows you to spawn new processes, connect to
their input/output/error pipes, and obtain their return codes. This
module intends to replace several other, older modules and functions,
such as:
os.system
os.spawn*
os.popen*
popen2.*
commands.*
"""
Yeah. There's a really tricky word up there in the beginning of the
subprocess doc. "intends". In this context, it means that it is
currently the plan of the Python developers to replace said modules with
the subprocess module, *however*, that has not totally come about now.
If the doc had said, "This module *has replaced* several others", then I
would have to agree with you that the stated module docs should be
updated to reflect the fact that they have been deprecated.
Since i'm not Python expert
Really?
, i like to look at these. But fuck, the incompetent doc gives ample gratis links to OpenSource this or that or author masturbation
OK - I just scanned through the subprocess module docs and I really
don't see where you're getting this from. I'll just chalk the former up
to your bad experience with the regular expression module docs referring
to the book "Mastering Regular Expressions." And since you're quite the
linguistic scholar, I'll chalk up the latter to your unique construction
of the book title I just cited.
links to remote book i don't really care about, but here there's no link.
Problem summary:
* does not focus on the task users need to do. Instead, the doc is oriented towards tech geeking.
Are you talking about the subprocess docs? If so, I'd like to see an
example of what you're talking about. Subprocess docs seem really
straightforward, terse, and to the point.
* does not inform the reader at the right place where a new function is replacing the old.
I would leave it in the hands of the Python doc maintainers what to do
with this since subprocess hasn't yet totally replaced the other modules.
* does not provide relevant cross-links. (while provding many irrelevant links because of OpenSource or Tech Geeking fanaticism)
I'd really like to see what you're talking about here. I just went
through the subprocess docs *again* and I don't see *any* links to any
other open source anything and I don't see any "tech geeking" to use
your jargon. I think you're full of crap. And I think you don't have
the balls to reply back to this message and show me what you're talking
about. You're just a little boy inside, making a call to a bowling
alley and asking if they have 15 pound balls and hanging up laughing
after they reply "yes" and you reply "Then how do you walk!!!" Oh,
you're so witty.
Solution Suggestion:
* Add examples.
Yeah, the
"""
6.8.3.2 Replacing shell pipe line
output=`dmesg | grep hda`
==>
p1 = Popen(["dmesg"], stdout=PIPE)
p2 = Popen(["grep", "hda"], stdin=p1.stdout)
output = p2.communicate()[0]
"""
subprocess module
"""
6.8.3.3 Replacing os.system()
sts = os.system("mycmd" + " myarg")
==>
p = Popen("mycmd" + " myarg", shell=True)
sts = os.waitpid(p.pid, 0)
"""
just
"""
6.8.3.4 Replacing os.spawn*
P_NOWAIT example:
pid = os.spawnlp(os.P_NOWAIT, "/bin/mycmd", "mycmd", "myarg")
==>
pid = Popen(["/bin/mycmd", "myarg"]).pid
P_WAIT example:
retcode = os.spawnlp(os.P_WAIT, "/bin/mycmd", "mycmd", "myarg")
==>
retcode = call(["/bin/mycmd", "myarg"])
Vector example:
os.spawnvp(os.P_NOWAIT, path, args)
==>
Popen([path] + args[1:])
Environment example:
os.spawnlpe(os.P_NOWAIT, "/bin/mycmd", "mycmd", "myarg", env)
==>
Popen(["/bin/mycmd", "myarg"], env={"PATH": "/usr/bin"})
"""
doesn't have
"""
6.8.3.5 Replacing os.popen*
pipe = os.popen(cmd, mode='r', bufsize)
==>
pipe = Popen(cmd, shell=True, bufsize=bufsize, stdout=PIPE).stdout
pipe = os.popen(cmd, mode='w', bufsize)
==>
pipe = Popen(cmd, shell=True, bufsize=bufsize, stdin=PIPE).stdin
(child_stdin, child_stdout) = os.popen2(cmd, mode, bufsize)
==>
p = Popen(cmd, shell=True, bufsize=bufsize,
stdin=PIPE, stdout=PIPE, close_fds=True)
(child_stdin, child_stdout) = (p.stdin, p.stdout)
(child_stdin,
child_stdout,
child_stderr) = os.popen3(cmd, mode, bufsize)
==>
p = Popen(cmd, shell=True, bufsize=bufsize,
stdin=PIPE, stdout=PIPE, stderr=PIPE, close_fds=True)
(child_stdin,
child_stdout,
child_stderr) = (p.stdin, p.stdout, p.stderr)
(child_stdin, child_stdout_and_stderr) = os.popen4(cmd, mode, bufsize)
==>
p = Popen(cmd, shell=True, bufsize=bufsize,
stdin=PIPE, stdout=PIPE, stderr=STDOUT, close_fds=True)
(child_stdin, child_stdout_and_stderr) = (p.stdin, p.stdout)
"""
any examples
"""
6.8.3.6 Replacing popen2.*
*Note:* If the cmd argument to popen2 functions is a string, the command
is executed through /bin/sh. If it is a list, the command is directly
executed.
(child_stdout, child_stdin) = popen2.popen2("somestring", bufsize, mode)
==>
p = Popen(["somestring"], shell=True, bufsize=bufsize
stdin=PIPE, stdout=PIPE, close_fds=True)
(child_stdout, child_stdin) = (p.stdout, p.stdin)
(child_stdout, child_stdin) = popen2.popen2(["mycmd", "myarg"], bufsize, mode)
==>
p = Popen(["mycmd", "myarg"], bufsize=bufsize,
stdin=PIPE, stdout=PIPE, close_fds=True)
(child_stdout, child_stdin) = (p.stdout, p.stdin)
"""
at all.
* Add cross-links to relevant modules.
Bah. Whatever. I've wasted enough time on this thread. I think the
only reason I read your posts is because you're just so comically and
consistently off base.
* Mention and add link at the right place supplanted functions.
* Orient the doc to tasks and manifest functionalities. Think like functional programing: input and output specification, and document them. This will help focus and precision in the doc. Avoid prose-like descriptions. Avoid drilling on remotely related tech/unix/C esoterica. e.g. Do not mention as a documentation how they are implemented. Mention implementation on the side if necessary. This way, the language becomes focused as a independent tool (e.g. Mathematica, Java, Scheme, emacs) (which may provide ample capabilities to interface/connect to other technologies), instead of heavily intermixed and dependent with a bunch of other things (unix things: Perl, Apache, shells).
----------------------------- This article is archive at: http://xahlee.org/UnixResource_dir/w...on_doc_os.html
Xah xa*@xahlee.org ∑ http://xahlee.org/
JMJ
Xah Lee schrieb: 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 well-named-ness:
import os os.system("ls")
however, according to the doc http://www.python.org/doc/2.4/lib/os-process.html the os.system() returns some esoteric unix thing, not the command output. The doc doesn't say how to get the output of the command.
The os.popen(...) function will return a file like object, so you can
use a read() - method of these object to get the called programms output.
hope that helps - I' m very new to python
The documentation may be not well for all circumstances but the fine
thing is: the documentation is part of the code itself - inform of the
docstrings - and this is a very good approach. The bad thing is the
person who wrote the docstring was documenting his/her own code and not
code of other programmers. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Anthony_Barker |
last post by:
I have been reading a book about the evolution of the Basic
programming language. The author states that Basic - particularly
Microsoft's version is full of compromises which crept in along the...
|
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...
|
by: mike420 |
last post by:
I think everyone who used Python will agree that its syntax is
the best thing going for it. It is very readable and easy
for everyone to learn. But, Python does not a have very good
macro...
|
by: Ixokai |
last post by:
Hello all. :)
I've been a long time Python fan, and have fairly recently (with the
support of a coworker who surprised me by mentioning my pet language one
day) convinced my company to begin the...
|
by: corey.coughlin |
last post by:
Alright, so I've been following some of the arguments about enhancing
parallelism in python, and I've kind of been struck by how hard things
still are. It seems like what we really need is a more...
|
by: mystilleef |
last post by:
Hello,
What is the Pythonic way of implementing getters and setters. I've
heard
people say the use of accessors is not Pythonic. But why? And what is
the alternative? I refrain from using them...
|
by: Edward Diener No Spam |
last post by:
The definition of a component model I use below is a class which allows
properties, methods, and events in a structured way which can be
recognized, usually through some form of introspection...
|
by: DJRhino |
last post by:
Was curious if anyone else was having this same issue or not....
I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM)
The start time is equivalent to 19:00 (7PM) in Central...
|
by: Aliciasmith |
last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
|
by: tracyyun |
last post by:
Hello everyone,
I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
|
by: giovanniandrean |
last post by:
The energy model is structured as follows and uses excel sheets to give input data:
1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
|
by: NeoPa |
last post by:
Introduction
For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM)
Please note that the UK and Europe revert to winter time on...
|
by: nia12 |
last post by:
Hi there,
I am very new to Access so apologies if any of this is obvious/not clear.
I am creating a data collection tool for health care employees to complete. It consists of a number of...
|
by: NeoPa |
last post by:
Introduction
For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
| |