file print extra spaces

bruce bushby bruce.bushby at gmail.com
Tue Mar 22 21:54:53 EDT 2011


Run your script and "pipe" the output to "| od -c"  the octal dumper will
show you what characters you're printing.....I'm guessing python's "print"
is adding one and each line in your file contains another.

You can also use a "," in python.... I forget the exact syntax, something
like "print(line),"  to prevent the carriage return from "print", but
ideally you should clean up the line if it's contaminated without unexpected
characters.


Bruce



On Wed, Mar 23, 2011 at 1:33 AM, monkeys paw <monkey at joemoney.net> wrote:

> When i open a file in python, and then print the
> contents line by line, the printout has an extra blank
> line between each printed line (shown below):
>
> >>> f=open('authors.py')
> >>> i=0
> >>> for line in f:
>        print(line)
>        i=i+1
>        if i > 14:
>                break
>
>
> author_list = {
>
>                  '829337' : {
>
>                                'author_name' : 'Carter, John',
>
>                                'count' : 49,
>
>                                'c2' : '0.102040816326531',
>
> How can i print the file out without having an extra newline between
> printed lines?
>
> Thanks for the help all.
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20110323/012985c6/attachment-0001.html>


More information about the Python-list mailing list