"Jack Jansen" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] | | On 12-Jan-2007, at 19:01 , Guido van Rossum wrote: | | > On 1/12/07, A.M. Kuchling <[EMAIL PROTECTED]> wrote: | >> Many types in Python are idempotent, so that int(1) works | >> as expected, float(2.34)==2.34, ''.join('hello')=='hello' | >> et cetera. | > | > I'm not sure I understand the use case; I don't believe I've ever felt | > the need for this. | | I have oodles of routines of the form | def foo(thefile): | if type(thefile) == str: thefile = open(thefile) | or | if not hasattr(thefile, 'read'): thefile = open(thefile) | or something similar.
This strikes me as being pretty directly analogous with functions that take either an iterable or iterator as argument for a parameter, and which start with 'it = iter(iterable)'. If we follow that analogy, file(fileob) should be the fileob itself, just as iter(iterator) == iterator. | > We should also consider the semantics in more detail. Should the seek | > position be shared between the two objects? What about buffering? | | That's definitely the hard part. But it's somewhat similar to | "normal" mutable objects which are (I think always, right?) shallow | copied when used in a constructor. But why, in the normal case, do you want a copy? It seems to me that is thefile is a file rather than a string, then that is what you want, and you are asking for 'thefile = file(thefile)' to work just as the iter statement does. Terry Jan Reedy _______________________________________________ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com