472,985 Members | 2,751 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

[NooB] Using Escape Sesquences with Strings...

Hello! :)
I've reading 'Python Programmin for the Absolute beginner'.
I got questions which is...

print "\t - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - "

rock = """
Igneous Sedimentary Metamorphic

Lava Grains Marble
Ramdom crystals Layer Bands
Granite Salt Schist
Intrusive Weathering Heat + Pressure
Deposition Change"""
print \trock

print "\t - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - "

error occurs!

I don't know how to \t The variable.

Help!
Jul 18 '05 #1
3 1286
administrata wrote:
print \trock


Your problem lies in this line. The escape sequence \t is not a
variable, so to speak. It is just that, an escape sequence, so it must
be located inside of a string:

print "\t" + rock

--
Daniel Bickett
dbickett at gmail.com
http://heureusement.org/
Jul 18 '05 #2
administrata wrote:
Hello! :)
I've reading 'Python Programmin for the Absolute beginner'.
I got questions which is...

print "\t - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - "

rock = """
Igneous Sedimentary Metamorphic

Lava Grains Marble
Ramdom crystals Layer Bands
Granite Salt Schist
Intrusive Weathering Heat + Pressure
Deposition Change"""
print \trock

print "\t - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - "

error occurs!

I don't know how to \t The variable.


see Daniel's answer for the why.
Now for the how, I guess you want a tab on each line so you have two
solutions :
1/ putting the tabs in the string:
rock = """
\tIgneous Sedimentary Metamorphic

\tLava Grains Marble
\tRamdom crystals Layer Bands
\tGranite Salt Schist
\tIntrusive Weathering Heat + Pressure
\t Deposition Change"""

print rock

2/ adding the tabs before printing:
rock = """
Igneous Sedimentary Metamorphic

Lava Grains Marble
Ramdom crystals Layer Bands
Granite Salt Schist
Intrusive Weathering Heat + Pressure
Deposition Change"""
for line in rock.split("\n"):
print "\t%s" % line

HTH,
--
bruno desthuilliers
ruby -e "print 'o****@xiludom.gro'.split('@').collect{|p|
p.split('.').collect{|w| w.reverse}.join('.')}.join('@')"
--
Jul 18 '05 #3
bruno modulix <on***@xiludom.gro> wrote in message news:<42*********************@news.free.fr>...
administrata wrote:
Hello! :)
I've reading 'Python Programmin for the Absolute beginner'.
I got questions which is...

print "\t - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - "

rock = """
Igneous Sedimentary Metamorphic

Lava Grains Marble
Ramdom crystals Layer Bands
Granite Salt Schist
Intrusive Weathering Heat + Pressure
Deposition Change"""
print \trock

print "\t - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - "

error occurs!

I don't know how to \t The variable.


see Daniel's answer for the why.
Now for the how, I guess you want a tab on each line so you have two
solutions :
1/ putting the tabs in the string:
rock = """
\tIgneous Sedimentary Metamorphic

\tLava Grains Marble
\tRamdom crystals Layer Bands
\tGranite Salt Schist
\tIntrusive Weathering Heat + Pressure
\t Deposition Change"""

print rock

2/ adding the tabs before printing:
rock = """
Igneous Sedimentary Metamorphic

Lava Grains Marble
Ramdom crystals Layer Bands
Granite Salt Schist
Intrusive Weathering Heat + Pressure
Deposition Change"""
for line in rock.split("\n"):
print "\t%s" % line

HTH,


thx 4 your helpful msg.

I'll input 1 instead of 2 which is a bit complicated for me.
Jul 18 '05 #4

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

Similar topics

4
by: areese801 | last post by:
i am using a website with a form that passes criteria to a javascript to run a query rather than just appending my criteria to parts of the URL. i need to import a bunch of records into MS...
7
by: teachtiro | last post by:
Hi, 'C' says \ is the escape character to be used when characters are to be interpreted in an uncommon sense, e.g. \t usage in printf(), but for printing % through printf(), i have read that %%...
18
by: Steve Litvack | last post by:
Hello, I have built an XMLDocument object instance and I get the following string when I examine the InnerXml property: <?xml version=\"1.0\"?><ROOT><UserData UserID=\"2282\"><Tag1...
3
by: Guadala Harry | last post by:
I'd like to know the answer to the following question so I can know what to expect with regard to other similar uses of escape characters and strings. While everything works fine - I'd like to know...
5
by: nummertolv | last post by:
Hi, My application is receiving strings, representing windows paths, from an external source. When using these paths, by for instance printing them using str() (print path), the backslashes are...
0
by: peridian | last post by:
Hi, I wanted a web page where I could post code to, and have it appear in coloured formatting based on the context of the code. Most of the techniques I have seen for this involve complex use...
4
by: JJ | last post by:
Is there a way of checking that a line with escape sequences in it, has no strings in it (apart from the escape sequences)? i.e. a line with \n\t\t\t\t\t\t\t\r\n would have no string in it a...
6
by: Lang Murphy | last post by:
I'm baaaaack... some of you answered a question I had last week. Only problem is: I'm a dope who doesn't understand most of what y'all posted. Raw noob when it comes to .Net and C#. So I'm going...
3
by: Richhpcnec | last post by:
I have two text strings that I have read from a text file. The text strings that I have read are the 8 characters each, 859c58d4 and 80434d43. I have assigned them the varible names of string1 and...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...

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.