Skip to content
  • YouTube
  • FaceBook
  • Twitter
  • Instagram

Data Analytics Ireland

Data Analytics and Video Tutorials

  • Home
  • Contact
  • About Us
    • Latest
    • Write for us
    • Learn more information about our website
  • Useful Links
  • Glossary
  • All Categories
  • Faq
  • Livestream
  • Toggle search form
  • Create a HTML Table From Python Using Javascript Javascript
  • What is Data Integrity? SQL
  • How to count the no of rows and columns in a CSV file CSV
  • YouTube channel lists – Python working with files Python working with files
  • What is Denormalization of data in a database? Working with databases
  • Why choose Julia over other programming languages? Julia programming
  • How to Create Multiple XML Files From Excel With Python Python
  • How to import data into excel Python Tutorial

TypeError: Array() Argument 1 Must Be A Unicode Character, Not List

Posted on June 11, 2022February 12, 2023 By admin

In a recent post, we discussed arrays and what they mean, and how they differ from lists. When you have a list in an array, one of the things that you need to define is what data type it is. If you don’t then the array will throw the error that you are on this page to resolve.

On the Python.org website, below is the list of values that can be populated to indicate what the data type of a list is in an array.

If you don’t add in the value you will get the below error:

ValueError: bad typecode (must be b, B, u, h, H, i, I, l, L, q, Q, f or d)

Let’s look at an example

import array as test_array

a = test_array.array([1,2,3])

print(a)

Gives an error of:
TypeError: array() argument 1 must be a unicode character, not list

As can be seen, the above logic tries to print a list within an array. The problem here is that an array can only be of one data type, and it has to be specified on the array creation.

How do we fix this?

It is quite simple! Before the list, we simply specify which type code we would like to apply from the above list. In this instance we are going to assign it as “signed int” that being the value “i” as follows:

import array as test_array

a = test_array.array("i",[1,2,3])

print(a)

Prints the following with no error:
array('i', [1, 2, 3])

Process finished with exit code 0

I can change the value “i” to any of the values I want from the above list, just picked that one to show as an example.

array, Python Lists, type error Tags:array, Data, Python, Python List, TypeError

Post navigation

Previous Post: How To Run Python Validation From Javascript
Next Post: How To Fix TypeError: unhashable type ‘slice’

Related Posts

  • TypeError: ‘NoneType’ object is not iterable class
  • how do I declare a null value in python? exception handling
  • TypeError: the first argument must be callable Python
  • How to Compare Column Headers in CSV to a List in Python CSV
  • How To Fix TypeError: unhashable type ‘slice’ python dictionaries
  • TypeError: ‘float’ object is not callable Python

Select your language!

  • हिंदी
  • Español
  • Português
  • Français
  • Italiano
  • Deutsch
  • How many python functions are there? Python
  • Explain different types of data Normalization. SQL
  • How to connect to your data in Tableau data visualisation
  • python constructor self and __init__explained Python
  • Tkinter GUI tutorial python – how to clean excel data Python
  • ValueError: invalid literal for int() with base 10 Value Error
  • How to Create Multiple XML Files From Excel With Python Python
  • How to run Python directly from Javascript Flask

Copyright © 2023 Data Analytics Ireland.

Powered by PressBook Premium theme

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Cookie settingsACCEPT
Privacy & Cookies Policy

Privacy Overview

This website uses cookies to improve your experience while you navigate through the website. Out of these cookies, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may have an effect on your browsing experience.
Necessary
Always Enabled
Necessary cookies are absolutely essential for the website to function properly. This category only includes cookies that ensures basic functionalities and security features of the website. These cookies do not store any personal information.
Non-necessary
Any cookies that may not be particularly necessary for the website to function and is used specifically to collect user personal data via analytics, ads, other embedded contents are termed as non-necessary cookies. It is mandatory to procure user consent prior to running these cookies on your website.
SAVE & ACCEPT