473,406 Members | 2,273 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,406 software developers and data experts.

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="\"..it 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 1733
Jim
Try using: tempname = "\\"
Jim
OriginalBrownster 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="\"..it 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
OriginalBrownster 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="\"..it 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
OriginalBrownster 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
OriginalBrownster 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="\"..it 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\balive!' # \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
OriginalBrownster 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.basename(path)

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

--
- Justin

Aug 21 '06 #6
Ant
such as tempname="\"..it 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\scripts\test.py"
path.split(filename)
('/home/ant', 'test.sh')
>>path.split(filename2)
('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
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...
13
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
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...
3
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 ...
15
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...
2
by: yesh81 | last post by:
Hi , can anybody write a java program to validate IP Addresses using string tokenizer.
13
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...
0
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...
4
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++ ) { ...
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...
0
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,...
0
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...

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.