473,383 Members | 1,919 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,383 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 1293
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...

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.