print "hello", >> file
phil hunt
philh at cabalamat.uklinux.net
Tue Feb 25 15:22:43 EST 2003
On Tue, 25 Feb 2003 13:47:04 -0500, Jp Calderone <exarkun at intarweb.us> wrote:
>
>--mYCpIKhGyMATD0i+
>Content-Type: text/plain; charset=us-ascii
>Content-Disposition: inline
>Content-Transfer-Encoding: quoted-printable
>
>On Tue, Feb 25, 2003 at 06:36:20PM +0000, phil hunt wrote:
>> On Tue, 25 Feb 2003 12:04:14 -0500, Peter Hansen <peter at engcorp.com> wrot=
>e:
>> >phil hunt wrote:
>> >>=20
>> >> Wouldn't it be nice if appending to a file, appending to a string
>> >> and appending to stdout had the same syntax?
>> >>=20
>> >> f =3D file("somefilename", "w")
>> >> f << "hello"
>> >>=20
>> >> s =3D "some string"
>> >> s << "hello"
>> >>=20
>> >> out << "hello"
>> >
>> >Since you can't append to a string,
>>=20
>> But I can:
>>=20
>> philh:~> python
>> Python 2.0 (#1, Jan 19 2001, 17:54:27)
>> [GCC 2.95.2 19991024 (release)] on linux2
>> Type "copyright", "credits" or "license" for more information.
>> >>>
>> >>>
>> >>> s =3D "some string"
>> >>> s +=3D "hello"
>> >>> s
>> 'some stringhello'
>> =20
>
> This rebinds "s" to a new string object. I suppose this hypothetical "<<"
>operator could do the same.
Indeed. IMOv it's irrelevant whether += (or <<, or whatever) is
implemented by modifying an existing object or binding to a new one
-- that's just an implementation detail, of no more significance
bthan whether the underlying processor is a Pentium or ARM.
> OTOH, why does anyone want yet -another- way to
>concatenate strings?
I don't particularly. I think that if Python had been designed from
scratch to use << for all 3, it'd be more concise and a cleaner
design -- but we are not designing Python from scratch.
--
|*|*| Philip Hunt <philh at cabalamat.org> |*|*|
|*|*| "Memes are a hoax; pass it on" |*|*|
More information about the Python-list
mailing list