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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T16:06:55+00:00 2026-06-17T16:06:55+00:00

I was bitten by the following numpy behaviour: In [234]: savetxt(open(‘/tmp/a.dat’, ‘wt’), array([1, 2,

  • 0

I was bitten by the following numpy behaviour:

In [234]: savetxt(open('/tmp/a.dat', 'wt'), array([1, 2, 3]))
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-234-2adef92da877> in <module>()
----> 1 savetxt(open('/tmp/a.dat', 'wt'), array([1, 2, 3]))

/local/gerrit/python3.2/lib/python3.2/site-packages/numpy/lib/npyio.py in savetxt(fname, X, fmt, delimiter, newline)
   1007         else:
   1008             for row in X:
-> 1009                 fh.write(asbytes(format % tuple(row) + newline))
   1010     finally:
   1011         if own_fh:

TypeError: must be str, not bytes

In [235]: savetxt(open('/tmp/a.dat', 'wb'), array([1, 2, 3]))
# success

I find this strange. I’m trying to save my array to a text file. Then why should I open the file in binary mode?

  • 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-17T16:06:56+00:00Added an answer on June 17, 2026 at 4:06 pm

    Because your data is bytes (ie binary) data.

    What comes out is still a text file. Don’t worry. 🙂 A “text” file is defined a something that contains only human readable text, not by in which mode you open it. The mode just makes a difference in how it handles the data given.

    Text mode means it expects Unicode data, and it will encode it into bytes format for you. Binary mode means it expects data in bytes, and will not encode it.

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

Sidebar

Related Questions

I need to export a huge php multidimensional array containing the following structure: [0]
I was just bitten by the following scenario: >>> -1 ** 2 -1 Now,
Encoding issues are among the one topic that have bitten me most often during
I've just been bitten by an annoying bug that was made obscure by the
I've recently been bitten by the javascript:void(null); bug in my hrefs when applied to
I've recently been bitten by the (way too commmon in my opinion) gotcha of
Sorry. I'm just bitten (or bit. Go figure with this left-to-right language :-) I've
Example: $arr = array( 'apple' => 'sweet', 'grapefruit' => 'bitter', 'pear' => 'tasty', 'banana'
I have on array like: $myarray = array(color, red, size, big, flavor, bitter); where
I am bitten by this little inconsistent debugger behavior. The quotemeta() function seems to

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.