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
  • How to use wildcards in SQL SQL
  • What are anonymous functions in Julia? array
  • String Manipulation in Python python method
  • How to create a combobox in tkinter Python
  • Create a HTML Table From Python Using Javascript Javascript
  • How to check if a file is empty Python
  • What does the … operator do in Julia? julia
  • How to use parameters in Python Python

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: cannot unpack non-iterable int object Python
  • TypeError: ‘int’ object is not callable Python
  • Python Tutorial: How to sort lists Python Lists
  • TypeError: type object is not subscriptable strings
  • YouTube channel lists – Python Lists Python Lists
  • TypeError: not all arguments converted during string formatting Python

Select your language!

  • हिंदी
  • Español
  • Português
  • Français
  • Italiano
  • Deutsch
  • How To Compare CSV Files for Differences CSV
  • How to create a class in Python class
  • What is the r programming language R Programming
  • How can I filter my data in Tableau? data visualisation
  • What is Julia used for? Julia programming
  • What is Apache Spark and what is it used for? Apache Spark
  • YouTube channel lists – Python working with files Python working with files
  • Python tutorial: How to create a graphical user interface in Tkinter Python

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