Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8148075
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T14:34:34+00:00 2026-06-06T14:34:34+00:00

For input text files, I know that .seek and .tell both operate with bytes,

  • 0

For input text files, I know that .seek and .tell both operate with bytes, usually – that is, .seek seeks a certain number of bytes in relation to a point specified by its given arguments, and .tell returns the number of bytes since the beginning of the file.

My question is: does this work the same way when using other encodings like utf-8? I know utf-8, for example, requires several bytes for some characters.

It would seem that if those methods still deal with bytes when parsing utf-8 files, then unexpected behavior could result (for instance, the cursor could end up inside of a character’s multi-byte encoding, or a multi-byte character could register as several characters).

If so, are there other methods to do the same tasks? Especially for when parsing a file requires information about the cursor’s position in terms of characters.

On the other hand, if you specify the encoding in the open() function …

infile = open(filename, encoding=’utf-8′)

Does the behavior of .seek and .tell change?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T14:34:35+00:00Added an answer on June 6, 2026 at 2:34 pm

    Assuming you’re using io.open() (not the same as the builtin open()), then using text mode gets you an instance of a io.TextIO, so this should anwser your question:

    Text I/O over a binary storage (such as a file) is significantly
    slower than binary I/O over the same storage, because it implies
    conversions from unicode to binary data using a character codec. This
    can become noticeable if you handle huge amounts of text data (for
    example very large log files). Also, TextIOWrapper.tell() and
    TextIOWrapper.seek() are both quite slow due to the reconstruction
    algorithm used
    .

    NOTE: You should also be aware, that this still doesn’t guarantee that seek() will skip over characters, but rather unicode codepoints (a single character can be composed out of more then one codepoint, for example ą can be written as u'\u0105' or u'a\u0328' – both will print the same character).

    Source: http://docs.python.org/library/io.html#id1

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a linux utility that parses structured input ( a text file ),
I am trying to read in a text input file that contains a list
I'm writing a personal wiki-style program in Python that stores text files in a
I know that its possible to reference third party JavaScript files on the web
I have a list of text files file1.txt, file2.txt, file3.txt .. filen.txt that I
I know that the line endings used for files vary depending on the OS.
We all know that App Engine limits you to 1 MB for most input/output
I'm making a program that uses text files. I need to make it so
I have a list of objects (created from several text files) in C#.net that
My raw input file text file contains a string: Caf&eacute (Should be Café) The

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.