Sysop: | Amessyroom |
---|---|
Location: | Fayetteville, NC |
Users: | 23 |
Nodes: | 6 (0 / 6) |
Uptime: | 40:47:52 |
Calls: | 583 |
Calls today: | 1 |
Files: | 1,138 |
Messages: | 110,394 |
Can you think of anything I'm missing?
"""Copies text file named S to text file named D."""
Ethan Carter <ec1828@somewhere.edu> wrote or quoted:
Can you think of anything I'm missing?
The correctness of a program as a solution to an assignment
depends on the exact wording of the assignment, so it's a
bit difficult to say without seeing it.
"""Copies text file named S to text file named D."""
This is not entirely clear, since case is significant in Python
("S" is not the same as "s"), and it is ambiguous whether it refers
to a file actually named "S" or to a file whose name is provided as
a str object bound to the name "s" in the function's source code.
You're right. There's no written statement. The exercise was suggested
by the teacher while in class. It was something like ``write a program
that copies text files by getting source and destination via the >command-line.''
But, yeah, if the Python community doesn't do that, it's all what you
say.
PS. Is it just me or there's just us in this used-to-be-very-active
group? Thanks for being my teacher here. Have a good day!
"""Copies text file named S to text file named D."""
This is not entirely clear, since case is significant in Python
("S" is not the same as "s"), and it is ambiguous whether it refers
to a file actually named "S" or to a file whose name is provided as
a str object bound to the name "s" in the function's source code.
This is how docstrings are traditionally written in GNU EMACS ELISP code---they upcase argument names of the procedure being documented. I
can't recall who taught me this, but I believe it was Robert Chassel in
his book ``An Introduction to Emacs Lisp'' that's included in the GNU
EMACS itself.
def copy(s, d):
"""Copies text file named S to text file named D."""
with open(s) as src:
with open(d, "w") as dst:
try:
dst.write(src.read())
except Exception:
os.remove(d)
raise
def copy(s, d):
"""Copies text file named S to text file named D."""
with open(s) as src:
with open(d, "w") as dst:
try:
dst.write(src.read())
except Exception:
os.remove(d)
raise
11 copy("/proc/sys/kernel/random/uuid", "/dev/full")
PS. Is it just me or there's just us in this used-to-be-very-active
group? Thanks for being my teacher here. Have a good day!
Ethan Carter <ec1828@somewhere.edu> wrote or quoted:
def copy(s, d):
"""Copies text file named S to text file named D."""
with open(s) as src:
with open(d, "w") as dst:
try:
dst.write(src.read())
except Exception:
os.remove(d)
raise
In Python there are several ways to format docstrings.
One possibility is to use conventions from "Sphinx" and to use
"reStructuredText". Then, it might look as follows, giving some
prominence to the names of parameters, though some find that
this is already too much markup in the source code:
"""
Copy the contents of the text file whose path is given by the
parameter ``s`` to the text file whose path is given by ``d``.
:param s: Path to the source text file to copy from.
:type s: str
:param d: Path to the destination text file to copy to.
:type d: str
:raises OSError: If an I/O error occurs during writing. On error,
the destination file will be removed if it was
partially written.
"""
Sphinx can then extract such documentation from your source code
and generate webpages or PDF books from it.
I don't know if Sphinx can extract types from type hints but,
Until a few months ago, there was a gateway that forwarded messages
both ways between this newsgroup and a mailing list. It seems to
have stopped working around the time mailing list appears to have
been been migrated to a different system.