[Tutor] string on multiple lines

Magnus Lycka magnus@thinkware.se
Wed Nov 13 10:13:20 2002


At 13:38 2002-11-12 -0500, Chris Kassopulo wrote:
>Greetings,
>
>I have a long string that I want to test.  I've tried \,
>single quotes, triple quotes - how does one have a string
>across multiple lines in a script ?

 >>> a = 'abc'\
... '123'\
... 'ABC'
 >>> print a
abc123ABC
 >>> b = '''abc
... 123
... ABC'''
 >>> print b
abc
123
ABC
 >>> c = 'abc\n'\
... '123\n'\
... 'ABC'
 >>> print c
abc
123
ABC
 >>> a == b
0
 >>> a == c
0
 >>> b == c
1

But what are really trying to do? It seems that you might really want:

if test_string not in ["Series","Denomination","Serial Number",
     "Issue Date","Price","Interest","Value","Rate","Yield",
     "Next Interest Date","Final Maturity Date","Note",
     "Cash/Exchange Date"]:

This will put you inside the if-block if your test_string is
neither of ""Series","Denomination" etc.

If you really want to test against the long string which
in itself contains strings, you have to clarify what you really
want. Is it a long line, or does it have line breaks? Should
the four spaces before e.g. "Issue Date" really be there?

As a general tip, I'd suggest that you did something like:

refString = '''"Series","Denomination","Serial Number",
     "Issue Date","Price","Interest","Value","Rate","Yield",
     "Next Interest Date","Final Maturity Date","Note",
     "Cash/Exchange Date"'''

print refString
print "compared with"
print test_string

if test_string != refString:
    ...

The print statements will probably give you some hints.


-- 
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