[Tutor] Re: Hello new to python and the mailing list, need some help

Nick Lunt nick at javacat.f2s.com
Sun May 30 14:46:56 EDT 2004

Hi Kevin,

you can stop python appending its own newline with a comma,


print line_a,
print line_b,


Hope that helps

  -----Original Message-----
  From: tutor-bounces at python.org [mailto:tutor-bounces at python.org]On Behalf
Of K J
  Sent: 30 May 2004 19:13
  To: tutor at python.org
  Subject: [Tutor] Re: Hello new to python and the mailing list, need some

  Thank you to all that help me on that. I got it to write seperate lines
  out useing any loops. Thanks for telling my about the upper case thing I
  not know that. Here is the code I made:

  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+'\n')
  player.write (age+'\n')
  player.write (sex+'\n')

  player = open("name.plr", 'r')
  line_a = player.readline()
  line_b = player.readline()
  line_c = player.readline()

  print line_a
  print line_b
  print line_c

  The output is like this



  Is there a way to bring the lines closer to gether? Sorry for all the
  questions I still have not had time to go buy a Python book, I have only
  been reading what I can on the internet and most of the tutorials don't
  explain this stuff.
  Thanks again,

  ----- Original Message -----
  From: "Alan Gauld" <alan.gauld at blueyonder.co.uk>
  To: "K J" <game at gameweave.com>; <tutor at python.org>
  Sent: Sunday, May 30, 2004 12:49 PM
  Subject: Re: [Tutor] Hello new to python and the mailing list, need some

  > Hi Kevin, welcome to Python.
  > There are several points to mke, only one of which
  > actually resolves your problem :-)
  > > ...I want to write to a seperate line so that it will
  > > print on the screen like this:
  > > 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? ")
  > First, by convention all uppercase letters are usually
  > reserved for fixed values or constants. Its just a convention
  > but a pretty well respected one. A mnore normal convention
  > for variable names is to keep then lower case and capitalize
  > any secondary words within the name., like this:
  > aLongName
  > It doesn't change how the code works but makes it easier
  > for other people to read your code.
  > > player = open("name.plr", 'w')
  > > player.write (NAME)
  > You are writing the data but the data has no newline at the end.
  > You need to add it. Unfortunately python files have a readline()
  > method but no writeline() - for reasons which have always puzzled me!
  > To add the newline we use the character sequence:
  > '\n'
  > so to write to the file you need to do:
  > player.write(NAME+'\n')
  > > player = open("name.plr", 'r')
  > > line = player.readline()
  > > player.close()
  > This will only read one line of input, if you need to read the
  > others you will either have to add multiple lines like the above
  > or use a loop - which you may not have come across yet in whatever
  > tutor you are following!
  > HTH,
  > Alan G
  > Author of the Learn to Program web tutor
  > http://www.freenetpages.co.uk/hp/alan.gauld/tutor2
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20040530/57c8dfa0/attachment.html

More information about the Tutor mailing list