[Tutor] Raw string

Steve Willoughby steve at alchemy.com
Sun Jul 20 17:48:30 CEST 2008


Neven Goršić wrote:
> Hi!
> 
> In every manual and book I read only one way to make a raw string:
> r"e:\mm tests\1. exp files\5.MOC-1012.exp".
> I don't know how to make a string raw string if it is already
> contained in a variable.
> s.raw() or something like that ...

Actually, there's no such thing as a "raw string" once it's constructed 
and sitting as an object in the runtime environment, or "contained in a 
string" as you stated.  It's just a string.  Raw strings simply refer to 
how the string constant value is assembled by the Python interpreter as 
the string object is being constructed.  In other words, it simply 
affects how the source code itself is understood to represent the string 
value.

r"e:\mm tests\1. exp files\5.MOC-1012.exp" will create a string object 
with the characters "e:\mm tests\1. exp files\5.MOC-1012.exp".  But now 
that's just a string value.  From here on out, those are simply a 
collection of those individual character values and won't be interpreted 
further.

"e:\mm tests\1. exp files\5.MOC-1012.exp" will create a string object 
with the characters "e:\mm tests^A. exp files^E.MOC-1012.exp".  But now 
that's just a string value with those characters.  There's no concept of 
"making it a raw string" after that point at all.
> 
> 
> 
> Thank you very much
> 
> PS. It seems like a very basic question but I can not find the answer
> in few books.
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor



More information about the Tutor mailing list