February 2006
Intermediate to advanced
648 pages
14h 53m
English
The built-in function open(name [,mode [,bufsize]]) opens and creates a file object, as shown here:
f = open('foo') # Opens 'foo' for reading
f = open('foo','r') # Opens 'foo' for reading (same as above)
f = open('foo','w') # Open for writingAlthough less common, files can also be created by calling the file object constructor, which is identical to open(). For example:
f = file('foo') # Opens 'foo' for reading
f = file('foo','w') # Open for writingThe file mode is ‘r’ for read, ‘w’ for write, or ‘a’ for append. The mode character can be followed by ‘b’ for binary data, such as ‘rb’ or ‘wb’. This is optional on UNIX, but it’s required on Windows and should be included if you are concerned about portability. In addition, ...
Read now
Unlock full access