Python 令吾混淆的檔案開啟函數
os.open()
os.fdopen()
open() [built-in, 內建的函數]
//===
http://stackoverflow.com/questions/15039528/what-is-the-difference-between-os-open-and-os-fdopen-in-python
""" ...
In short, open() creates new file objects,
os.open() creates OS-level file descriptors, and
os.fdopen() creates a file object out of a file descriptor.
...
Built-in open() takes a file name and returns a new Python file object.
This is what you need in the majority of cases.
... """
--> 一般來說, 直接用內建的 open() 就好了.
[example]
fd = os.open( "foo.txt", os.O_RDWR|os.O_CREAT )
# fd is file descriptor
fo = os.fdopen(fd, "w+")
fo.write( "I am a pig.\nYou are, too.\n");
# fo is file object
fo2 = open("foo.txt", "wb")
fo2.write( "who are you?\nwho's who?\n");
# fo is file object, too.
http://www.tutorialspoint.com/python/python_files_io.htm
No comments:
Post a Comment