473,769 Members | 1,752 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

trouble using "\" as a string

Hi there...

I'm still pretty new to turbogears. but i have gotten pretty familiar
with it

i'm just trying to clear something up, i'm having a difficult time
using \ when declaring a string expression

such as tempname="\"..i t says that the line is single qouted.

i want this because using python I am pulling in filenames from a
mac..thus they are "/" in the pathways..and i want to .split it at the
"/" to obtain the filename at the end...but its proving diffucult with
this obstacle in the way.

Why is this happening??

Aug 19 '06 #1
6 1746
Jim
Try using: tempname = "\\"
Jim
OriginalBrownst er wrote:
Hi there...

I'm still pretty new to turbogears. but i have gotten pretty familiar
with it

i'm just trying to clear something up, i'm having a difficult time
using \ when declaring a string expression

such as tempname="\"..i t says that the line is single qouted.

i want this because using python I am pulling in filenames from a
mac..thus they are "/" in the pathways..and i want to .split it at the
"/" to obtain the filename at the end...but its proving diffucult with
this obstacle in the way.

Why is this happening??
Aug 19 '06 #2
that stores tempname as "\\"

...
Jim wrote:
Try using: tempname = "\\"
Jim
OriginalBrownst er wrote:
Hi there...

I'm still pretty new to turbogears. but i have gotten pretty familiar
with it

i'm just trying to clear something up, i'm having a difficult time
using \ when declaring a string expression

such as tempname="\"..i t says that the line is single qouted.

i want this because using python I am pulling in filenames from a
mac..thus they are "/" in the pathways..and i want to .split it at the
"/" to obtain the filename at the end...but its proving diffucult with
this obstacle in the way.

Why is this happening??
Aug 19 '06 #3
OriginalBrownst er wrote:
[I un-bottom-posted this]
Jim wrote:
>Try using: tempname = "\\"
Jim
that stores tempname as "\\"

..
I don't think so. I think you just think it's storing it as that
because if you enter it at the interactive prompt it shows '\\'. But
try len(tempname) and see if it's 1.

--
--OKB (not okblacke)
Brendan Barnwell
"Do not follow where the path may lead. Go, instead, where there is
no path, and leave a trail."
--author unknown
Aug 20 '06 #4
OriginalBrownst er wrote:
Hi there...

I'm still pretty new to turbogears. but i have gotten pretty familiar
with it

i'm just trying to clear something up, i'm having a difficult time
using \ when declaring a string expression

such as tempname="\"..i t says that the line is single qouted.

i want this because using python I am pulling in filenames from a
mac..thus they are "/" in the pathways..and i want to .split it at the
"/" to obtain the filename at the end...but its proving diffucult with
this obstacle in the way.

Why is this happening??
In Python (and many other programming languages), the backslash is the
"escape character". That is, special characters are indicated by
sequences that start with a backslash.
>>print 'Line 1\nLine 2' # \n = newline
Line 1
Line 2
>>print 'tab\tseparated \ttext' # \t = tab
tab separated text
>>print 'This parrot is dead\b\b\b\bali ve!' # \b = backspace
This parrot is alive!
>>print 'The ASCII code for \x41 is 0x41.'
The ASCII code for A is 0x41.
>>'It\'s necessary to escape a quote that\'s within the same type of quote.'
"It's necessary to escape a quote that's within the same type of
quote."

An escape sequence is always considered a single character. (As
mentioned earlier, you can verify this with the len function.) Thus,
your "\" gets parsed as:

" = opening quote of string
\" = double quotation mark (escaped)
end of line = error, because no closing quote was found

If you want a backslash, you have to escape *it* with a backslash: "\\"

Aug 20 '06 #5
OriginalBrownst er wrote:
i want this because using python I am pulling in filenames from a
mac..thus they are "/" in the pathways..and i want to .split it at the
"/" to obtain the filename at the end...but its proving diffucult with
this obstacle in the way.
sounds like you want
import posixpath
posixpath.basen ame(path)

assuming you are on a windows box,otherwise the normal os.path.basenam e
will do it.

--
- Justin

Aug 21 '06 #6
Ant
such as tempname="\"..i t says that the line is single qouted.
The others have addressed the escape issue I think. However it looks
like you want the funtionality of the os.path module. For example:
>>import os.path as path
filename = "/home/ant/test.sh"
filename2 = r"c:\python24\s cripts\test.py"
path.split(fi lename)
('/home/ant', 'test.sh')
>>path.split(fi lename2)
('c:\\python24\ \scripts', 'test.py')

Aug 21 '06 #7

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

Similar topics

2
3855
by: Sebastien Degardin | last post by:
Hello, I need to use a Factory pattern to create services class. i have an interface --> MyService i can have an abstract class --> MyAbstractService i have several concrete class for this service --> MyServiceVersion1_1 MyServiceVersion1_2. I would like to create a factory which could instantiate object using
13
141254
by: Squid Seven | last post by:
This is just bizarre. for the following snippet of code: #include <string> using std::string; I get the error message:
1
1840
by: Prasad Dabak | last post by:
Hello, I have a legacy unmanaged application that returns property=value pairs separated by chr(252)and I am trying to parse this output from C# using string.split method. This works fine as long as the default locale is en-US. However, the moment, I change it to say Greek/Portuguese, the parsing logic goofs up. I don't have access to the source code of legacy application to make changes.
3
5166
by: Jonay Aloat | last post by:
I need to implement the following. Shoul I use multimap or write a string hash class? ie Brand Product ========================== Samson Television Samsung Television Samsung VCR Samsung DVD Player Samsunk Television
15
2681
by: arnuld | last post by:
-------- PROGRAMME ----------- /* Stroustrup, 5.6 Structures STATEMENT: this programmes *tries* to do do this in 3 parts: 1.) it creates a "struct", named "jd", of type "address". 2. it then adds values to "jd" 3.) in the end it prints values of "jd".
2
4950
by: yesh81 | last post by:
Hi , can anybody write a java program to validate IP Addresses using string tokenizer.
13
2931
by: marathoner | last post by:
I would like to read the following entries of mixed data types from a ascii text file using C#. This can be easily performed in C using fscanf. Is there an equivalent function in C#? 1 2 1201 1 -0.417597000000000D+06 0.129600000000000D+06 0.0 0.753000000000000D+03 0.198800000000000D+04 Marathoner
0
13756
NeoPa
by: NeoPa | last post by:
Intention : To prepare a WHERE clause for multiple field selection, but to ignore any fields where the selection criteria are not set. ONLY WORKS WITH TEXT FIELD SELECTIONS. Scenario : You have a table (tblMember) containing information for various people. Table Name=tblMember Field; Type; IndexInfo MemberID; AutoNumber; PK Surname; String
4
1426
by: Dev | last post by:
Can replacing this with stringbuilder advisable. Or since iteration is less only 20 times, the time taken by using strings and string builder will be the same. for( int i = 0; i< 20; i++ ) { strCell2 = "<input type=hidden id='Id" + rwCnt + "' name='id" + rwCnt + "' value='" + ID + "' />" + "<input type=hidden id='hidId" + rwCnt + "' name='hidId" + rwCnt + "' value='" + kEntityName + "' />" + "<input type=hidden id='setupType" + ID + "'...
0
10212
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...
0
8872
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
7410
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
6674
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5304
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...
0
5447
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3962
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
3563
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2815
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.