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), readline () < / code> on it I saw that the tell () function also counts the end of the line.

My question:

  1. How to instruct the code to leave the end of the line?

  2. How to do the first question without regard to the line completion type (only in the case of using a text file, \ 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]   

    The bad news is that it is more annoying to do this just to see it at tell The good news is that it answers your questions.

    Or, I think you can

      yourfile.tell () - data_read .count ('\ r') - data_read.count ('\ n')    

Comments

Popular posts from this blog

Verilog Error: output or inout port "Q" must be connected to a structural net expression -

jasper reports - How to center align barcode using jasperreports and barcode4j -

c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -