Re: File Reading related query

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Fredrik Lundh

    Re: File Reading related query

    Usman Ajmal wrote:
    Is there any function for reading a file while ignoring *\n* occuring in
    the file?
    can you be a bit more precise? are we talking about text files or
    binary files? how do you want to treat any newlines that actually
    appear in the file?

    </F>

  • r0g

    #2
    Re: File Reading related query

    Fredrik Lundh wrote:
    Usman Ajmal wrote:
    >
    >Is there any function for reading a file while ignoring *\n* occuring
    >in the file?
    >
    can you be a bit more precise? are we talking about text files or
    binary files? how do you want to treat any newlines that actually
    appear in the file?
    >
    </F>
    >
    Hi Usan,

    I've always just done...

    for each in open('filename. txt', 'r'):
    each = each.rstrip()

    You could wrap this as a generator if you really want it to be a one
    liner, personally it's never seemed worth it to me.

    Regards,


    Roger Heathcote



    Comment

    Working...