Python: New Line in files?

Discussion in 'Mac Programming' started by Nsutton, Apr 16, 2010.

  1. Nsutton macrumors member

    Nsutton

    Joined:
    Dec 29, 2009
    Location:
    6 Feet Under
    #1
    When writing to a file, how do you tell python to format the text and enter to the next line?

    -Thanks
     
  2. Bostonaholic macrumors 6502

    Bostonaholic

    Joined:
    Aug 21, 2009
    Location:
    Columbus, Ohio
    #3
    I don't know what you mean by "format the text".

    Newlines are different for linux/mac vs. windows/dos

    For *nix systems, including Mac
    Code:
    print("This is on the first line \n and this is on the second.")
    For Windows/DOS machines
    Code:
    print("This is on the first line \r\n and this is on the second.")
     
  3. Nsutton thread starter macrumors member

    Nsutton

    Joined:
    Dec 29, 2009
    Location:
    6 Feet Under
  4. chuckles:) macrumors 6502

    Joined:
    May 3, 2006
    Location:
    CANADA
    #5
    You can also add the newline character (\n) to the end of your line.
    For instance:

    writeline("Hello.\n")

    will result in a new line at the \n point.
     

Share This Page