468,765 Members | 811 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,765 developers. It's quick & easy.

[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 1219
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by areese801 | last post: by
18 posts views Thread by Steve Litvack | last post: by
3 posts views Thread by Guadala Harry | last post: by
5 posts views Thread by nummertolv | last post: by
4 posts views Thread by JJ | last post: by
6 posts views Thread by Lang Murphy | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.