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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T17:03:59+00:00 2026-05-28T17:03:59+00:00

The following code, executed in python 2.7.2 on windows , only reads in a

  • 0

The following code, executed in python 2.7.2 on windows, only reads in a fraction of the underlying file:

import os

in_file = open(os.path.join(settings.BASEPATH,'CompanyName.docx'))
incontent = in_file.read()
in_file.close()

while this code works just fine:

import io
import os

in_file = io.FileIO(os.path.join(settings.BASEPATH,'CompanyName.docx'))
incontent = in_file.read()
in_file.close()

Why the difference? From my reading of the docs, they should perform identically.

  • 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-28T17:04:00+00:00Added an answer on May 28, 2026 at 5:04 pm

    You need to open the file in binary mode, or the read() will stop at the first EOF character it finds. And a docx is a ZIP file which is guaranteed to contain such a character somewhere.

    Try

    in_file = open(os.path.join(settings.BASEPATH,'CompanyName.docx'), "rb")
    

    FileIO reads raw bytestreams and those are “binary” by default.

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

Sidebar

Related Questions

I execute following code on windows xp and python 2.6.4 But it show IOError.
I'm playing with the Python library httplib2 . The following is my code. import
I am trying to execute the following code in Python import os,subprocess from glob
I executed the following code: import sys x=sys.argv[1] print x; if x > 1:
I want to execute python code from C# with following code. static void Main(string[]
I have the following Python code: cursor.execute("INSERT INTO table VALUES var1, var2, var3,") where
Assuming A.sql contains the following code, then second Select query won’t be executed due
I have used following code to create a simple PDF file. It executes fine
I have the following code: import sqlite3 con = sqlite3.connect(testDB) cur = con.cursor() #cur.execute('CREATE
Following code, using python 2.6.6 and MySQLdb 1.2.2 causes Commands out of sync; 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.