473,699 Members | 2,734 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 4057
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...@gm ail.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("Ente r 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
5351
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 code below in the Web.Config file defines the authentication as forms and the aspx file required for login if the user is unauthenticated... this works well for the root level company web pages however when a user viewing the website of SubCompanyA...
2
1634
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 code below in the Web.Config file defines the authentication as forms and the aspx file required for login if the user is unauthenticated... this works well for the root level company web pages however when a user viewing the website of SubCompanyA...
1
2818
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 C++ application, thru ODBC. I'm able to successfully open a connection to the DB and perform selects, but when I try to do an insert the strangest thing happens, ODBC throws an error saying that it can't open the "dba.mdb" file, which is not the db...
2
1948
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 driver issue. I'm having the strangest behavior when trying to do an insert into an access database from a C++ application, thru ODBC. I'm able to successfully open a connection to the DB and perform selects, but when I try to do an insert the...
0
8612
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9171
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8905
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7743
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6532
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4373
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3053
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2342
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2008
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.