[Tutor] file operations and formatting
Magnus Lycka
magnus@thinkware.se
Tue Dec 17 20:53:02 2002
At 11:09 2002-12-17 -0500, Mike P wrote:
>Is there some difference between using open('whatever','w') and
>file('whatever','w')?
See
http://www.python.org/doc/current/lib/built-in-funcs.html
The background is the new style classes, and the union of
types and classes. For more about that, read:
http://www.python.org/doc/current/whatsnew/sect-rellinks.html#SECTION000310000000000000000
The idea is that the builtin types should behave as
classes. You should be able to subclass string or
int or file, to extend them with new features. Then
it makes sence that the name of the class is also used
as a constructor. Right?
If you do
calls Person:
def __init__(fname, lname):
self._fname = fname
self._lname = lname
p = Person('Brian', 'Cohen')
to instanciate a Person object, you should be able to do
f = file('hello.txt', 'w')
to instanciate a file object.
--
Magnus Lycka, Thinkware AB
Alvans vag 99, SE-907 50 UMEA, SWEDEN
phone: int+46 70 582 80 65, fax: int+46 70 612 80 65
http://www.thinkware.se/ mailto:magnus@thinkware.se