[Tutor] string on multiple lines
Chris Kassopulo
ckasso@sprynet.com
Wed Nov 13 12:02:25 2002
On Wed, 13 Nov 2002 16:19:53 +0100
Magnus Lycka <magnus@thinkware.se> wrote:
> 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 ?
> 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?
It is the first line of a .csv file. I read it with readlines
and replace '\r\n' with ''. No breaks or spaces. I've tried
some mutations of your suggestions and what I can get to work is:
(shortened for wordwrap)
if 1:
ref_string='"Series","Denomination","Serial Number","Issue Date"'
tst_string='"Series",\
"Denomination",\
"Serial Number",\
"Issue Date"'
print ref_string
print "compared with"
print tst_string
if tst_string != ref_string:
print "error: not a valid csv file"
else:
print 'ref_string is same as tst_string'
but this doesn't work because of the leading spaces:
tst_string='"Series",\
"Denomination",\
"Serial Number",\
"Issue Date"'
just found that this works:
tst_string='"Series",' + \
"Denomination",' + \
"Serial Number",' + \
"Issue Date"'
any other way ?
Chris Kassopulo