Hot to split string literals that will across two or more lines ?
Steve Holden
steve at holdenweb.com
Wed Nov 23 04:33:09 EST 2005
Mohammad Jeffry wrote:
> 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
>
>
[...]
In your particular case, if it really is SQL you're dealing with then
you shouldn't worry about what it looks like when you print it - the SQL
interpreter certainly won't care.
Many SQL statements are so long that it actually helps readability to
have newlines in them.
There have been plenty of solutions presented in the earlier posts in
this thread if you really do need to represent multi-line strings.
regards
Steve
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC www.holdenweb.com
PyCon TX 2006 www.python.org/pycon/
More information about the Python-list
mailing list