[Tutor] Help..Concatenaton Error

Martin Walsh mwalsh at mwalsh.org
Fri Jun 12 04:12:59 CEST 2009


ayyaz wrote:
> Randy Trahan wrote:
>> Attached is an error I cannot get to work, I was doing a print
>> concatenation but it won't let me get past "+ "ibly impressive. " \
>> (then to next line)
>>  
>> Also Programming Lanquage Question:
>> I have studied and an fairly proficient at XHTML and CSS, I tried
>> Javascript but just didn't like it for some reason..so I am trying
>> Python which so far fits my personality, needs, whatever that part is
>> that makes you choose a lanquage. Will I be able to use Python in web
>> pages as I would of used Javascript?  From what I have read there are
>> Python to Javascript converters?...

The only python to javascript project I am aware of is pyjamas
(http://pyjs.org/), which is a python port of the Google Web Toolkit.
Not sure if that's exactly what you're looking for. There are several
javascript libraries available now-a-days that help make programming
javascript more like programming in python. Mochikit comes to mind
(http://www.mochikit.com/). But, I'm not a web developer.

>>  
>> Thanks in advance..
>> -- 
>> Randy Trahan
>> Owner, BullDog Computer Services, LLC
>> 478-396-2516
>
> Hello Randy,
> 
> You have two plus signs after "+ "ibly impressive. " \.
> 
> That might be the problem.

And, it appears you've missed the quote before "\nThis string ", as well.

Perhaps also important to note, the line continuation character '\' may
not be followed by any character on the same line, including whitespace,
so ...

print "\nThis string " + \<space>
        "may not"

... where <space> indicates the presence of ... er, well ... a
whitespace character, would be invalid (a SyntaxError).

PEP8 (http://www.python.org/dev/peps/pep-0008/) outlines some
alternatives to the line continuation character. For example,

 >>> s = ("This is a " +
 ... "long line" +
 ... ".")
 >>> s
 'This is a long line.'

Or, you can leave out the +, as string concatenation is implicit in the
following ...

 >>> s = ("This is a "
 ... "long line"
 ... ".")
 >>> s
 'This is a long line.'

... but, beware -- it's easy to overlook when constructing a list (or
tuple).


 >>> lst = ['This is a',
 ... 'long' # <- missing comma
 ... 'line',
 ... '.']
 >>> lst
 ['This is a', 'longline', '.']

HTH,
Marty


More information about the Tutor mailing list