Hot to split string literals that will across two or more lines ?

Mohammad Jeffry linuxlah at gmail.com
Wed Nov 23 04:24:26 EST 2005


I tried to use this method in my code like this:-
---------------------------------------------------------------------------------
#!/usr/bin/python


def print_sql():
    sql = '''aaaaaaaaaaaaaaaaaaaaaaa
    bbbbbbbbbbbbbbbbbbbbbbb'''.replace("\n","")
    print sql

print_sql()

---------------------------------------------------------------------------------

the ouput of this is aaaaaaaaaaaaaaaa<space><tab>bbbb......

I can always do this :-
---------------------------------------------------------------------------------
#!/usr/bin/python


def print_sql():
    sql = '''aaaaaaaaaaaaaaaaaaaaaaa
bbbbbbbbbbbbbbbbbbbbbbb'''.replace("\n","")
    print sql

print_sql()

---------------------------------------------------------------------------------

but it looks ugly


On 11/22/05, Mohammad Jeffry <linuxlah at gmail.com> wrote:
>
>
> On 11/22/05, Paul McGuire <ptmcg at austin.rr._bogus_.com> wrote:
>
> > Or for a large literal string:
> >
> > """
> > lots of text hundreds of characters long
> > more text on another line but we really don't want any line breaks
> > in our final string
> > so we replace newlines in this multiline string
> > with an empty string thus
> > """.replace('\n','')
> >
> > -- Paul
>
>
>
> I love your method. The only drawbacks for this method is I can't tell
> whether there is blank space at the end of each lines. For EG: the above
> string might be
>
> lots of text hundreds of characters longmore text on another.....
>                                                         ^
> or
>
> lots of text hundreds of characters long more text on another.....
>                                                         ^
>
>
>
>
>
> --
> And whoever does an atom's weight of evil will see it.




--
And whoever does an atom's weight of evil will see it.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20051123/97971a4a/attachment.html>


More information about the Python-list mailing list