[Tutor] Hello new to python and the mailing list, need some help
Glen Wheeler
gew75 at hotmail.com
Sun May 30 01:24:48 EDT 2004
Hi Kevin,
Escape codes are special characters used in strings to represent things
which we find hard to put into simple letters.
For example, the escape code for a newline is `\n'. So,
print '\n'
will actually print *two* blank lines. There is a little inconsistency
with Python's file handling in that the print command will automatically add
a newline after any output, but a file.write(..) will not.
As a further hint, string concatenation is formed with the `+' operator.
So that
d = 'dog'
c = 'cat'
s = c+d
print s // 'catdog'
Now, I'm sure you can figure out how to get newlines into your file :).
Glen
----- Original Message -----
From: K J
To: tutor at python.org
Sent: Sunday, May 30, 2004 1:30 PM
Subject: [Tutor] Hello new to python and the mailing list, need some help
Hello, I am new to python and need a little help. I am trying to write to a
file but wich i can the only problem that I have is that Each raw_input I
want to write to a seperate line so that it will print on the screen like
this:
Kevin
27
Male
right now it just prints to the screen like this:
Kevin27Male
here is the code that I did:
NAME = raw_input("What is your name? ")
AGE = raw_input ("What is your age? ")
SEX = raw_input ("What is your sex? ")
player = open("name.plr", 'w')
player.write (NAME)
player.write (AGE)
player.write (SEX)
player.close()
player = open("name.plr", 'r')
line = player.readline()
player.close()
print line
Thanks for any help
Kevin
_______________________________________________
Tutor maillist - Tutor at python.org
http://mail.python.org/mailman/listinfo/tutor
More information about the Tutor
mailing list