Python Single Spaced Output?

Discussion in 'Mac Programming' started by CaptainZap, Feb 14, 2008.

  1. macrumors regular

    Joined:
    Jan 17, 2007
    #1
    How come it seems when Python outputs things to Terminal, everything is double spaced? Like this is the output from Python
    [​IMG]

    And this is from the cat command
    [​IMG]

    And yes, it is an ice cream cone. Anyways, is there a way to change this?
     
  2. Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #2
    Post some code?
     
  3. thread starter macrumors regular

    Joined:
    Jan 17, 2007
    #3
    If you had this in a text file
    Code:
         .-"`'"-.
       /        \
       |        |
       /'---'--`\
      |          |
      \.--.---.-./
      (_.--._.-._)
        \=-=-=-/
         \=-=-/
          \=-/
           \/
    And then used this Python code
    Code:
    for line in open('textfile.txt','r'):
    	print line
    
    It looks like the first picture, and then this looks like the second picture

    Code:
    cat textfile.txt
     
  4. Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #4
    From the Python Reference Manual:

    So change your code to:

    Code:
    for line in open('textfile.txt','r'):
    	print line,
     
  5. thread starter macrumors regular

    Joined:
    Jan 17, 2007
    #5
    Well played sir, thank you. I had read that too, I just thought it allowed you to write to the same line :p
     
  6. Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #6
    It does if you add the comma. But "line" already contains a \n from the text file, so that is creating the new line.
     

Share This Page