Raw Strings with Variables

Jan Kaliszewski zuo at chopin.edu.pl
Tue Aug 18 20:30:36 EDT 2009


Dnia 19-08-2009 o 02:09:29 WilsonOfCanada <wwn1 at sfu.ca> napisał(a):

> You're right, but the moment I append it onto a list, it would become
> C:\\moo.

No, it would not. Really!

>  C:\moo
>  C:\supermoo
>  ['C:\\moo', 'C:\\supermoo']

It is not the matter of content of the string but only of a way of
*presentation* of it by print:

     print arrPlaces

in the example is roughly equivalent to:

     print '[' + repr(a_list[0]) + ', ' + repr(a_list[1]) + ']'


So try:

     print a_list[0]
Output:
     C:\moo

     print a_list[1]
Output:
     C:\supermoo

     print ', '.join(arrPlaces)
Output:
     C:\moo, C:\supermoo

     print ', '.join("'%s'" % item for item in arrPlaces)
Output:
     'C:\moo', 'C:\supermoo'


Cheers,
*j

-- 
Jan Kaliszewski (zuo) <zuo at chopin.edu.pl>



More information about the Python-list mailing list