Mailing List Archive

Raw Strings!
Hi All
If someone could show me how to use raw-strings with variables, I
would really appreciate it.
For e.g.: if str_path = "C:\\windows\\temp"

thanks
Sunit
Raw Strings! [ In reply to ]
On Sat, Jun 12, 1999 at 10:30:16AM -0500, SunitJoshi wrote:
> From: "SunitJoshi" <smjoshi@bellsouth.net>
> Newsgroups: comp.lang.python
> Subject: Raw Strings!
> Date: Sat, 12 Jun 1999 10:30:16 -0500
> To: python-list@python.org
>
> Hi All
> If someone could show me how to use raw-strings with variables, I
> would really appreciate it.
> For e.g.: if str_path = "C:\\windows\\temp"
>

var = r"D:\\stupid\\windows\\path"

note the "r" of "raw" before the string. This is always the case.

9 minutes and i reply... hmm, not bad :-)

regards,
Gerrit.
Raw Strings! [ In reply to ]
"'Gerrit Holl" <gerrit@nl.linux.org>, '@humbolt.nl.linux.org writes:

> On Sat, Jun 12, 1999 at 10:30:16AM -0500, SunitJoshi wrote:
[...]
> >
> > Hi All
> > If someone could show me how to use raw-strings with variables, I
> > would really appreciate it.
> > For e.g.: if str_path = "C:\\windows\\temp"
> >
>
> var = r"D:\\stupid\\windows\\path"
>
> note the "r" of "raw" before the string. This is always the case.

I don't think this is what is wanted here... Try

r"C:\windows\temp"

instead. The point with raw strings is that backslashes can be written
out without being escaped.

>
> 9 minutes and i reply... hmm, not bad :-)

Well - not too good either, considering that you gave a misleading
answer <wink>

>
> regards,
> Gerrit.
>
>

--

Magnus Making no sound / Yet smouldering with passion
Lie The firefly is still sadder / Than the moaning insect
Hetland : Minamoto Shigeyuki
Raw Strings! [ In reply to ]
SunitJoshi wrote:

> Hi All
> If someone could show me how to use raw-strings with variables, I
> would really appreciate it.
> For e.g.: if str_path = "C:\\windows\\temp"
>
> thanks
> Sunit

Since I suspect you have path-strings like the above in mind, may I suggest
simply
using forward slashes - they will work on win98. Else I recommend using
'os.sep'.

Anders Moe
Raw Strings! [ In reply to ]
"Magnus L. Hetland" wrote:
>
> The point with raw strings is that backslashes can be written
> out without being escaped.

Be warned that raw strings are not *quite* completely
raw! For example,

s = r"\abc\def\"

is a syntax error. On the other hand,

s = r"\abc\def\\"

is not. I'll leave you with the fun of trying to
guess what the resulting string contains...

They-should-really-be-called-rare-strings,
Greg