473,804 Members | 2,126 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

String backslash characters

PD
Hello,

I am new to python, but i am quite curious about the following.

suppose you had

print '\378'

which should not work because \377 is the max. then it displays two
characters (an 8 and a heart in my case...). What else does'nt quite
make sense is that if this is an octal why is an 8 accepted?

for instance is 378 really 11, 111, 1000 which is then the two
characters: <00000001>,<111 1000>. And why is this accepted?

I apologize if this has been discussed or if it is obvious. I would
appreciate it if someone could clear me up.

Yours,
PD

Jul 18 '05 #1
4 1882
PD wrote:
Hello,

I am new to python, but i am quite curious about the following.

suppose you had

print '\378'

which should not work because \377 is the max. then it displays two
characters (an 8 and a heart in my case...). What else does'nt quite
make sense is that if this is an octal why is an 8 accepted?


Because 8 isn't an octal digit, so it's not part of the escape
sequence, but a separate character. It's just like

print 'This string\47s escape sequence does not include the s.'

Your example displays two characters because it is two characters:
'\037' and '8'.

Jul 18 '05 #2
PD wrote:
Hello,

I am new to python, but i am quite curious about the following.

suppose you had

print '\378'

which should not work because \377 is the max. then it displays two
characters (an 8 and a heart in my case...). What else does'nt quite
make sense is that if this is an octal why is an 8 accepted?


It's not doing quite what you think. The '\37' is seen as octal, but
since '8' isn't a valid octal digit, it's seen as the literal character '8'.

In other words, these two lines are equivalent:
'\378' '\x1f8' '\37' + '8'

'\x1f8'
Jul 18 '05 #3
'\378' becomes a two character string. The first character is '\37'
and the second character is '8'.
str = '\378'
str[0] '\x1f' str[1] '8'

On 23 Dec 2004 20:53:13 -0800, PD <al*****@gmail. com> wrote: Hello,

I am new to python, but i am quite curious about the following.

suppose you had

print '\378'

which should not work because \377 is the max. then it displays two
characters (an 8 and a heart in my case...). What else does'nt quite
make sense is that if this is an octal why is an 8 accepted?

for instance is 378 really 11, 111, 1000 which is then the two
characters: <00000001>,<111 1000>. And why is this accepted?

I apologize if this has been discussed or if it is obvious. I would
appreciate it if someone could clear me up.

Yours,
PD

--
http://mail.python.org/mailman/listinfo/python-list

Jul 18 '05 #4
PD wrote:
I am new to python, but i am quite curious about the following.

print '\378'

which should not work because \377 is the max. then it displays two
characters (an 8 and a heart in my case...). What else does'nt quite
make sense is that if this is an octal why is an 8 accepted?


It would appear that the parser reads \377 as a single character and
\378 as two (\37 and the "8" character). I'm somewhat surprised you're
seeing a heart and an 8. What OS/language combination are you using?
If you're using English Windows you can get a heart and an "8" with
"print '\38'".
--
Benji York
be***@benjiyork .com

Jul 18 '05 #5

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

Similar topics

3
15882
by: Vincent Texier | last post by:
Hello, I want to send 3 chars in hexa code to the serial port. So I type in a tkinter entry : "\x20\x01\x21" The string is set in a StringVar(). When I read the stringVar, I get : "\\x20\\x01\\x21"
5
3023
by: John Baro | last post by:
I have a richtextbox which I want the "literal" rtf of. richtextbox.rtf returns {\\rtf1\\ansi\\ansicpg1252\\deff0\\deflang1033\\uc1 }\r\n\0 when i put this into a string I get "{\\rtf1\\ansi\\ansicpg1252\\deff0\\deflang1033\\uc1 }\r\n\0" I want this to be @"{\\rtf1\\ansi\\ansicpg1252\\deff0\\deflang1033\\uc1 }\r\n\0" to treat the escape characters as literals
4
7472
by: Guadala Harry | last post by:
I need to place the following into a string... How can I properly escape the % " / < and > characters? <table width="100%" border="0" cellspacing="0" cellpadding="4px" class="hfAll"></Table> Thanks.
3
18795
by: Brian | last post by:
I have an XML file that I want to read in and pass as a string to a stored procedure. I am having trouble getting the file into a string. I am using a TextReader to read the file in, but my string that I end up with has a backslash character in front of all the double quotes. How do I get a string from my file that doesn't have all these extra characters? Is there an easier way to do this. Here is the code I am using to read the file. ...
32
14917
by: tshad | last post by:
Can you do a search for more that one string in another string? Something like: someString.IndexOf("something1","something2","something3",0) or would you have to do something like: if ((someString.IndexOf("something1",0) >= 0) || ((someString.IndexOf("something2",0) >= 0) ||
4
3431
by: weirdstuff | last post by:
Hi. I have this simple code: =========================================== ->Database query here (.. some code) $row=mysql_fetch_array($res); (...)
5
1720
by: Jayson Davis | last post by:
Say I have a string read from a configuration file. searchfor <tab> Needle\n\n Where I want to search for the word "Needle" with two linefeeds. Now when I read it from the file, it hasn't converted the linefeeds into characters. Is there a function to do that or do I need to write it myself?
6
1749
by: OriginalBrownster | last post by:
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.
6
303
by: HMS Surprise | last post by:
The string s below has single and double qoutes in it. For testing I surrounded it with triple single quotes. I want to split off the portion before the first \, but my split that works with shorter strings does not seem to work with this one. Ideas? Thanks, jvh
5
3279
by: cameljs18 | last post by:
Converting a string variable into a string literal. How do I add the @ character in front of the string? I cannot add it when the string is created as it will affect other parts of the program. I have tried these but they do not work: label1.text = @S label1.text = "@" + S
0
9711
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9593
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
10595
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
10343
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9169
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
7633
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
5529
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
5668
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4306
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

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.