diff options
author | Guido van Rossum <guido@python.org> | 1996-11-14 14:10:11 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 1996-11-14 14:10:11 (GMT) |
commit | c59120ba1730b65d1f4b475ebd11f5ecf7780e03 (patch) | |
tree | 95fd34d0c05bc729db58c177c577e8d62684da4a | |
parent | caa83c4b9e5d8920cccf5f14a17ddcfa5a60e634 (diff) | |
download | cpython-c59120ba1730b65d1f4b475ebd11f5ecf7780e03.zip cpython-c59120ba1730b65d1f4b475ebd11f5ecf7780e03.tar.gz cpython-c59120ba1730b65d1f4b475ebd11f5ecf7780e03.tar.bz2 |
Added os.remove()/unlink(), rmdir(), rename(), and [f]truncate().
-rw-r--r-- | Misc/FAQ | 17 |
1 files changed, 17 insertions, 0 deletions
@@ -179,6 +179,7 @@ Here's an overview of the questions per chapter: 4.39. Q. How to implement persistent objects in Python? (Persistent == automatically saved to and restored from disk.) 4.40. Q. I try to use __spam and I get an error about _SomeClassName__spam. + 4.41. Q. How do I delete a file? And other file questions. 5. Extending Python 5.1. Q. Can I create my own functions in C? @@ -1708,6 +1709,22 @@ A. Variables with double leading underscore are "mangled" to provide a simple but effective way to define class private variables. See the chapter "New in Release 1.4" in the Python Tutorial. +4.41. Q. How do I delete a file? And other file questions. + +A. Use os.remove(filename) or os.unlink(filename); for documentation, +see the posix section of the library manual. They are the same, +unlink() is simply the Unix name for this function. In earlier +versions of Python, only os.unlink() was available. + +To remove a directory, use os.rmdir(); use os.mkdir() to create one. + +To rename a file, use os.rename(). + +To truncate a file, open it using f = open(filename, "w+"), and use +f.truncate(offset); offset defaults to the current seek position. +There's also os.ftruncate(fd, offset) for files opened with os.open() +-- for advanced Unix hacks only. + 5. Extending Python =================== |