473,394 Members | 2,020 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

r"<path>"

Is there a way to use the 'r' in front of a variable instead of
directly in front of a string? Or do I need to use a function to get
all of the slashes automatically fixed?

/thanks
-Kyle
Sep 30 '08 #1
5 4042
Kyle Hayes wrote:
Is there a way to use the 'r' in front of a variable instead of
directly in front of a string? Or do I need to use a function to get
all of the slashes automatically fixed?
Please describe the actual problem you're trying to solve. In what way
do slashes need to be "fixed," and why?

--
Carsten Haese
http://informixdb.sourceforge.net
Sep 30 '08 #2
Please describe the actual problem you're trying to solve. In what way
do slashes need to be "fixed," and why?
Well, I have decided to build a tool to help us sync files in UNC
paths. I am just building the modules and classes right now so I
haven't developed the frontend yet. I am assuming when the user
provides a path (either by typing it in, or pulling it in from a
config file), the UNC slashes are going to escape stuff in the string,
so I want to double them up.

I understand if the best way is to convert all the slashes to double-
slashes. But the 'r' function seemed so handy and convenient.

I am very new to Python, but not at all to programming.

Thanks!
Sep 30 '08 #3
On Sep 30, 1:17*pm, Kyle Hayes <mrkyleha...@gmail.comwrote:
Is there a way to use the 'r' in front of a variable instead of
directly in front of a string? Or do I need to use a function to get
all of the slashes automatically fixed?
Is this what you're talking about?

str = "foo/bar"
re = Regexp.new(str) =/foo\/bar/

-- Mark.
Sep 30 '08 #4
Kyle Hayes wrote:
>Please describe the actual problem you're trying to solve. In what way
do slashes need to be "fixed," and why?

Well, I have decided to build a tool to help us sync files in UNC
paths. I am just building the modules and classes right now so I
haven't developed the frontend yet. I am assuming when the user
provides a path (either by typing it in, or pulling it in from a
config file), the UNC slashes are going to escape stuff in the string,
so I want to double them up.
That assumption is incorrect. While backslashes in string literals are
escape characters that must be doubled up to convey literal backslashes,
no such interpretation is made for backslashes that are read from a GUI
text box or from a file.

See for yourself:
>>some_string = raw_input("Enter a string: ")
Enter a string: blah\blah\blah
>>print some_string
blah\blah\blah

Carry on and come back when you actually have a problem ;)

--
Carsten Haese
http://informixdb.sourceforge.net
Sep 30 '08 #5
On Tue, 30 Sep 2008 10:50:01 -0700, Kyle Hayes wrote:
>Please describe the actual problem you're trying to solve. In what way
do slashes need to be "fixed," and why?

Well, I have decided to build a tool to help us sync files in UNC paths.
I am just building the modules and classes right now so I haven't
developed the frontend yet. I am assuming when the user provides a path
(either by typing it in, or pulling it in from a config file), the UNC
slashes are going to escape stuff in the string, so I want to double
them up.

I understand if the best way is to convert all the slashes to double-
slashes. But the 'r' function seemed so handy and convenient.
You don't need to. Python's string is never escaped in-memory, it is only
escaped when repr(s) is called (the interpreter's implicit print uses repr
() instead of str()). And that means all string coming and going to/from
IO (file, GUI, etc) is stored as-is. However, strings that comes from
source code or interpreter prompt (a.k.a. literal string) needs to be
escaped.

Analogy: When you're writing a string in the source code, you add double
quotes (""), right? But do you think the quotes are stored in memory? No,
it's just an escape character to differentiate a string from its
surrounding.

Sep 30 '08 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Murphy | last post by:
Our website contains subdirectories for each subsidiary company, each company has it's own look and feel to the pages in their subdirectory although they are all part of the main website. The...
2
by: Murphy | last post by:
Our website contains subdirectories for each subsidiary company, each company has it's own look and feel to the pages in their subdirectory although they are all part of the main website. The...
1
by: dryajov | last post by:
Hi I'm not sure if this should go here in the first place, this is more likely an ODBC driver issue. I'm having the strangest behavior when trying to do an insert into an access database from a...
2
by: dryajov | last post by:
NOTE TO MODERATOR: I'm reposting this thread here, please remove the duplicate from ACCESS/VBA forum. Thanks. Hi I'm not sure if this should go here in the first place, this is more likely an ODBC...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.