How to exclude \n and \r from tell() count in Python 2.7 -
I want to keep track of the file pointer on a simple text file (just a few lines), My question: How to instruct the code to leave the end of the line? How to do the first question without regard to the line completion type (only in the case of using a text file, The bad news is that it is more annoying to do this just to see it at Or, I think you can readline () < / code> on it I saw that the
tell () function also counts the end of the line.
\ n , or just
\ r , or both)?
tell is
. This cursor is counted by number of bytes from the beginning of the file, it is counted as
\ n and
\ r \ / code> bytes, so they are counted. If you want to calculate the number of bytes, but do not want to count some characters, then you have to do it manually:
data_read = รข ?? | # The data that you have already read [l] [b]
tell The good news is that it answers your questions.
yourfile.tell () - data_read .count ('\ r') - data_read.count ('\ n')
Comments
Post a Comment