[Tutor] ".=" in Python ?

Tadahiko 'kiko' Uehara kikofx@nifty.com
Mon May 5 17:04:01 2003


Thank you for the qucik reply !

On Mon, 5 May 2003 13:16:36 -0700
Brett Kelly <bkelly@sourcereview.net> wrote:

> 
> +=
> 
> a += b
> is the same as
> a = a + b

Sorry I wasn't clear in my previous post(obviouslly, subject too)...

perl:
	my $a .= $a."text";
	print $a;

Python:
	a = ""
	a += a + "test"
	print a

I thought I did something unnatural so I needed to say 1st line 'a = ""'.
Or Does it work like this?

Thanks,
-kiko

> 
> Sometime around Tue, May 06, 2003 at 05:08:37AM +0900, Tadahiko 'kiko' Uehara took the liberty of imparting these morsels of brilliance:
> > 
> > Hi all,
> > I just start learning Python as my (almost) first programming language.
> > 
> > I have a text file which contains something like:
> > ------------------------------
> > irc.foo1.com
> > irc.foo2.com
> > irc.foo3.com
> >  .
> >  .
> >  .
> > ------------------------------
> > 
> > and I'm trying to generate list as following:
> > ------------------------------
> > servername = irc.foo1.com
> > servername = irc.foo2.com
> > servername = irc.foo2.com
> >  .
> >  .
> >  .
> > ------------------------------
> > 
> > Here is my script...
> > 
> > #! /usr/bin/python
> > 
> > text = "servername = "
> > modLine = "" # <-- had to add this line,in order to *1 to work.
> >                                                                                         
> > f = open("/home/kiko/docs/serverList")
> > line = f.readline()
> > while line:
> >     modLine = modLine + text + line	# *1
> >     line = f.readline()
> > 
> > f.close()
> >                                                                                         
> > print modLine
> > ------------------------------------
> > 
> >  My question is, 
> > What would be an equivalent of Perl's ".=" in Python ? Is my A = A + B right way to do this ?
> > I'm curious this becuase I think don't need to state modLine = "" in either Shell Script or Perl.
> > 
> >  Also, If this mailing-list is active anymore? I checked list archives http://mail.python.org/pipermail/tutor/  But i only see 1-2 posts per recent month ..!?
> > 
> > Thanks in advance,
> > -kiko
> > 
> > _______________________________________________
> > Tutor maillist  -  Tutor@python.org
> > http://mail.python.org/mailman/listinfo/tutor
> 
> -- 
> Brett Kelly
> bkelly@sourcereview.net
> 
> This message was created using the Mutt mail agent and 
> digitally signed using GnuPG.
> 
>