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 4028286
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T11:12:07+00:00 2026-05-20T11:12:07+00:00

In the book – Core Python Programming, there is following example – >>> f

  • 0

In the book – Core Python Programming, there is following example –

>>> f = open('/tmp/x', 'w+')
>>> f.tell()
0
>>> f.write('test line 1\n')  # add 12-char string [0-11]
>>> f.tell()
12
>>> f.write('test line 2\n')  # add 12-char string [12-23]
>>> f.tell()                  # tell us current file location (end))
24

When I run the same code in my interpreter, I get 13L in place of 12 and 26L in place of 24.
I am running python 2.5 on Windows.

Has anything changed regarding behaviour or tell() in versions? How does tell decide the position in the file.

Thanks and Regards

  • 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-05-20T11:12:07+00:00Added an answer on May 20, 2026 at 11:12 am

    Your file is opened in text mode. In that mode Python on Windows makes a translation between Windows line-endings and Unix line endings. On Windows a line ending is two characters while on Unix it is one ('\n'), hence your result is expected.

    If you open the file in binary mode, you don’t get these translations.

    f = open('/tmp/x', 'wb+')
    

    And you would get 12 and 24 back from tell() as well.

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

Sidebar

Related Questions

In book named Using C++ by Rob McGregor there is following example of using
A book as the following example and explains that you won't see the line
I have a book called Scientific Programming with Python (2009), in which example code
The book I'm currently reading has me write the following code : -(IBAction)displaySomeText:(id)sender {
While reading the book Programming Ruby , one example shows how blocks can be
The book of IronPython In Action has the following code to read python script
The book, Producing Open Source Software , suggests that it's better to have lengthy
One Book(Object Oriented Programming with C++ by E.Balagurusamy) says that const size = 10;
In the The Django Book in chapter 6 about the Admin Site, they tell
The book of CLR via C# has this line at page 76. When you

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.