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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T07:10:33+00:00 2026-05-27T07:10:33+00:00

I have the following code (as an example) in a unittest TestCase def test(self):

  • 0

I have the following code (as an example) in a unittest TestCase

def test(self):
    a = array('u','\0'*3)
    a[0] = 'h'
    a[1] = 'h'
    a[2] = 'h'

    self.assertEqual(a.tostring(), "hhh")

The assertion fails with the following error:

AssertionError: b'h\x00\x00\x00h\x00\x00\x00h\x00\x00\x00' != 'hhh'

Now I understand that the array I created is for Unicode characters which are 4 bytes long hence the extra 3 NUL bytes for every character I entered. My questions are:

  1. Can I convert the string “hhh” into Unicode representation inline of my assert?
  2. Is there a ascii option to create my array with?

EDIT: to answer the questions that have come up:
1. I am using Python 3
2. array comes from module array, can be imported with: from array import array

  • 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-27T07:10:33+00:00Added an answer on May 27, 2026 at 7:10 am

    I suppose you are working with Python3, which seems to lack a 'c' option for array.

    In this case, I would do

    a = array.array("b",4*(0,))
    a[0] = 'h'
    a[1] = 'h'
    a[2] = 'h'
    

    Another option would be

    a=array.array('u', "hhh") # the same as yours, but shorter
    a.tounicode()
    

    But then you have a unicode string and not a bytes() object.

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

Sidebar

Related Questions

I have the following example code: class A(object): def __init__(self, id): self.myid = id
Say I have the following code: <div onclick='location.href=http://www.example.com/'> <a href='#' onclick='alert(blah)'>click</a> </div> Is there
On a report I have the following code for a field: =Sum([PartQty]*[ModuleQty]) Example results
Say suppose I have the following Java code. public class Example { public static
I have following code in my application. [self.navigationController pushViewController:x animated:YES]; It will push a
I have the following code example (see below). My problem is that the tooltip
I have the following example code: <body> <div id=a></div> <div id=b></div> </body> If I
If i have the following code example: public class ClassBase { public int ID
I have the following code for example $(a.foo).bind(function (e){ var t; if ( $(e.target).is(a)
I have the following example code: create table Details( name varchar(20), age int, weight

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.